欢迎分享,转载请注明来源:内存溢出
用全局临时表: ALTER procedure [dbo][Keyword_Query] (@table_name nvarchar(100)=N'' ,@col_name nvarchar(200)=N''--@col_name 格式为col1,col2,col3 ,@key_word nvarchar(200)=N'') as begin declare @sql nvarchar(2000) ; if ( @col_name =N''and @table_name <>N'') begin set @sql='select into ##t from '+@table_name+ ' where 1=2' exec sp_executesql @sql; DECLARE colCursor CURSOR FOR--设置游标遍历当前表的列名 select name from syscolumns where id=object_id(@table_name) OPEN colCursor FETCH NEXT FROM colCursor INTO @col_name WHILE @@FETCH_STATUS=0 BEGIN set @sql='insert into ##t select distinct from '+@table_name +' where '+ @col_name+' like '+ '''%'+@key_word+'%''' exec sp_executesql @sql;--将表内查询出的结果装入表 FETCH NEXT FROM colCursor INTO @col_name END close colCursor deallocate colCursor set @sql='select distinct from ##t' exec sp_executesql @sql;--去除表内的重复数据 set @sql='drop table ##t' exec sp_executesql @sql;--删除表 end end
赞
(0)
打赏
微信扫一扫
支付宝扫一扫
国外与国内远程控制问题!!高手进。。非常急。。
上一篇
2023-05-11
哪些业务需要办IDC许可证?
下一篇
2023-05-11
评论列表(0条)