SQL For xml path on int columns?

▼魔方 西西 提交于 2019-12-11 14:41:34

问题


Can I use FOR XML PATH in sql for int columns ? So that I could use it for something like:

declare @contactIds = (select id from contacts)

and then use it like this:

select * from calls where contactId in (@contactIds)

Is it possible ?


回答1:


Is this what you want?

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

You can also use a subquery directly or a table variable:

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

My guess is that your problem is more complex than the question, so this doesn't really solve the problem.



来源:https://stackoverflow.com/questions/22147235/sql-for-xml-path-on-int-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!