如何调用数组,做为子查询啊?

NOZMC 2015-07-17 11:51:29
一个字段里面的值是这样的。'3203,3211,3212,3213,3215,3300,3301,3302,3303,3305,3306,3307,3309,3310 '
如何便利这个数组变成这样啊?
select * from test where id in ('3203,3211,3212,3213,3215,3300,3301,3302,3303,3305,3306,3307,3309,3310 )
...全文
70 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
NOZMC 2015-07-17
已经自己搞好了。
回复
Tiger_Zhao 2015-07-17
DECLARE @table1 TABLE(a varchar(100))
INSERT INTO @table1 VALUES('3203,3211,3212,3213,3215,3300,3301,3302,3303,3305,3306,3307,3309,3310')

DECLARE @sql varchar(max)
SET @sql = 'select * from test where id in ('''
SELECT @sql = @sql + a FROM @table1
SET @sql = @sql + ''')'
EXEC(@sql)
回复
相关推荐
发帖
疑难问题
创建于2007-09-28

2.1w+

社区成员

MS-SQL Server 疑难问题
申请成为版主
帖子事件
创建了帖子
2015-07-17 11:51
社区公告
暂无公告