declare @val varchar(1000);select top 1 @val=stuff((select ','+cast(sfjlbh as varchar(10)) from sf_sfjl where jfsj>='2010-11-01' and jfsj<='2010-11-30' for xml path('')), 1, 1, '') from sf_sfjl 上面的sql语句应该是这样的串 @val='1,5,6,7'
但是下面我就要用到@val :select * from 表 where id in(@val)重点就在这里:@val 是个字符串 而in()要的是 in(1,5,6,7),这个问题怎么样处理才好? 高手帮帮忙!
但是下面我就要用到@val :select * from 表 where id in(@val)重点就在这里:@val 是个字符串 而in()要的是 in(1,5,6,7),这个问题怎么样处理才好? 高手帮帮忙!
不是这样的 in() 要的是int
而@val 是字符串
eg:
select * from 表 where id in(select [id] from 表 where [createtime]<getdate())
@strSql='select * from 表 where id in('+@val+')'
exec(@strSql)
with abc as
{
select ddt from sf_sfjl where jfsj>='2010-11-01' and jfsj<='2010-11-30'
}
select * from 表 where id in( select ddt from abc)列的名称相不相同无所谓,关键是类型要对
表值函数 用不了 exec方法 ,但是还是谢谢你