示例值:"548,549,550,551,712,713"
SQL Server 2016 及更高版本
Declare @ids nvarchar(200) = '123,456';对于旧版本 SQL Server 2005 - 2014
Select *
From Users
Where ID IN ( Select Value from STRING_SPLIT ( @ids , ',' ))
Declare @ids nvarchar(200) = '123,456'; --<-- Comma delimited list of Client Ids
Select *
From Users
Where ID IN (
SELECT CAST(RTRIM(LTRIM(Split.a.value('.', 'VARCHAR(100)'))) AS INT) IDs
FROM (
SELECT Cast ('<X>'
+ Replace(@ids, ',', '</X><X>')
+ '</X>' AS XML) AS Data
) AS t CROSS APPLY Data.nodes ('/X') AS Split(a)
)
- 本文标题: sqlserver id in @ 不能将nvarchar转int
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
- 上一篇:JSON常用语法大全
- 下一篇: android Fragment 返回键层层返回