以ååè¿ç±»ä¼¼çï¼åèä¸ä¸ï¼
declare @str nvarchar(20)
declare @tablename varchar(50)
declare @colname varchar(50)
declare @counts int
declare @sql nvarchar(2000)--以ä¸å®ä¹åé
declare cur1 cursor for
select a.name tablename,B.name colname from sys.objects a,syscolumns b where a.object_id=b.id and a.type_desc='USER_TABLE'--å®ä¹æ¸¸æ
set @str='CTæ è¢å¼è¸ä¸è¡£' --设置è¦æ¥æ¾çå符
Open cur1 --æå¼æ¸¸æ
Fetch next From cur1 Into @tablename,@colname
While(@@Fetch_Status = 0) --循ç¯
Begin
set @sql=N'select @counts=COUNT(*) from ' + @tablename + ' where charindex('''+@str+''','+@colname+')>0'
exec sp_executesql @sql,N'@counts int output',@counts output --æ§è¡å¨æsql
if @counts>0 --å¤ææ个表æ个å段æ¯å¦åå¨ç¹å®å符
begin
print @tablename+','+@colname --æå°è¡¨ååå段å
end
Fetch next From cur1 Into @tablename,@colname
End
Close cur1 --å
³é游æ
Deallocate cur1 --éæ¾æ¸¸æ
追é®æ¶æ¯ 4104ï¼çº§å« 16ï¼ç¶æ 1ï¼ç¬¬ 7 è¡
The multi-part identifier "B.name" could not be bound.
追çä»ä¹çæ¬sqlserverï¼è¿ç¨æ¹ä¾¿ä¸ï¼
追é®æçè¿ä½ 以ååçï¼ä½æ¯æ¥è¯¢ä¸ä¸ªæ©ä¸é½æ²¡æ¥å®