在int列上使用xml的SQL路径? [英] SQL For xml path on int columns?

查看:78
本文介绍了在int列上使用xml的SQL路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在sql中为int列使用FOR XML PATH吗? 这样我就可以将其用于类似这样的事情:

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)

然后像这样使用它:

select * from calls where contactId in (@contactIds)

有可能吗?

推荐答案

这是您想要的吗?

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.

这篇关于在int列上使用xml的SQL路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆