sql 将逗号分割的字符串存入临时表

来源:互联网 发布:sql 身份证号脱敏 编辑:程序博客网 时间:2024/05/16 23:54

if exists(select * from sysobjects where name = 'strToTable') 
drop proc strToTable
go


CREATE  proc dbo.strToTable
@gidstr nvarchar(4000)              --商品id
as
declare @xmlstr xml

set arithabort on

set @xmlstr=convert(xml,'<root><v>' + replace(@gidstr, ',', '</v><v>') + '</v></root>') 

select gid = N.v.value('.', 'int')  
into #tmp
FROM @Xmlstr.nodes('/root/v') N(v)

select * from #tmp

0 0
原创粉丝点击