IF EXISTS (SELECT name FROM sysobjects WHERE name = 'searchname' AND type = 'P') DROP PROCEDURE searchnameGocreate procedure searchname @sname varchar(10)Asbegincreate table #TableList( tablename char(200), colname char(200)) declare @table varchar(200)declare @col varchar(200) set nocount ondeclare curTab scroll cursor for select name from sysobjects where xtype='u'open curTabfetch next from curTab into @tablewhile @@FETCH_STATUS=0begin declare curCol scroll cursor for select name from syscolumns where (xtype=175 or xtype=167) and (id in (select id from sysobjects where name=@table)) open curCol fetch next from curCol into @col while @@FETCH_STATUS=0 begin execute('insert into #TableList select '''+@table+''','''+@col+''' from '+@table+' where '+@col+'='''+@sname+'''') fetch next from curCol into @col end close curCol deallocate curCol fetch next from curTab into @tableendclose curTabdeallocate curTabset nocount offselect distinct * from #TableListdrop table #tablelist end调用SearchName ‘张三’
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货