SQL对于int列上的xml路径?

时间:2014-03-03 12:47:50

标签: sql sql-server for-xml-path

我可以在sql中使用FOR XML PATH for int columns吗? 所以我可以用它来代替:

declare @contactIds = (select id from contacts)

然后像这样使用它:

select * from calls where contactId in (@contactIds)

有可能吗?

1 个答案:

答案 0 :(得分:2)

这是你想要的吗?

select @contactIds = stuff((select ','+cast(id as varchar(8000))
                            from contacts
                            for xml path('')
                           ), 1, 1, '');

您也可以直接使用子查询或表变量:

select *
from calls
where contactId in (select id from contacts);

我的猜测是你的问题比问题更复杂,所以这并没有真正解决问题。