1

我可以在 sql 中将 FOR XML PATH 用于 int 列吗?这样我就可以将其用于以下用途:

declare @contactIds = (select id from contacts)

然后像这样使用它:

select * from calls where contactId in (@contactIds)

可能吗 ?

4

1 回答 1

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);

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

于 2014-03-03T12:53:05.503 回答