How to convert comma separated NVARCHAR to table records in SQL Server 2005?

前端 未结 7 1679
走了就别回头了
走了就别回头了 2020-11-27 06:18

I have a list of ids separated by comma like:

 1,17,25,44,46,67,88

I want to convert them to a table records ( into a temporary table ) lik

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 06:41

    DECLARE @str VARCHAR(4000) = '6,7,7,8,10,12,13,14,16,44,46,47,394,396,417,488,714,717,718,719,722,725,811,818,832'
    
    DECLARE @x XML 
    select @x = cast(''+ replace(@str,',','')+ '' as xml)
    
    select t.value('.', 'int') as inVal
    from @x.nodes('/A') as x(t)
    

提交回复
热议问题