27,579
社区成员
发帖
与我相关
我的任务
分享
SET @sql='SELECT * FROM '+@table+' WHERE '+@column+' IN('+@biaojiHE+')'
select o.name, c.name
from syscolumns c
inner join sysobjects o on c.id = o.id
where o.type = 'u' and c.xtype in (167, 175, 231, 239) and (o.name in ( select 手机号码 from [案件信息表]))---用变量不行
order by o.name, c.name
--把上面sql替换成下面的就ok了
DECLARE @sql VARCHAR(max),
@biaojiHE VARCHAR(max)
SET @biaojiHE ='select 手机号码 from [案件信息表]'
SET @sql='select o.name, c.name
from syscolumns c
inner join sysobjects o on c.id = o.id
where o.type = ''u'' and c.xtype in (167, 175, 231, 239) and (o.name in ( '+@biaojiHE+'))
order by o.name, c.name
'
--PRINT @sql
EXEC (@sql)
DECLARE @sql VARCHAR(max),
@biaojiHE VARCHAR(max)
SET @biaojiHE ='select 手机号码 from [案件信息表]'
SET @sql='
declare tables cursor
for
select o.name, c.name
from syscolumns c
inner join sysobjects o on c.id = o.id
where o.type = ''u'' and c.xtype in (167, 175, 231, 239) and (o.name in ( '+@biaojiHE+'))
order by o.name, c.name
open tables
fetch next from tables into '+@table+','+@column
--PRINT @sql
EXEC (@sql)
把创建游标的sql也一起拼接进去就ok了