ChangeCharToTable

ALTER FUNCTION [dbo].[ChangeCharToTable]
(@InStatement NVARCHAR(MAX))
RETURNS @InTable TABLE
(
Id int not null primary key clustered
)
AS
BEGIN
DECLARE @XML as xml
set @XML='<t><i>' + REPLACE(@InStatement,',','</i><i>') + '</i></t>'

INSERT INTO @InTable
SELECT T.c.query('text()').value('.','int') as Id from @XML.nodes('/t/i') T(c)
RETURN
END

 

SELECT top 100 ID FROM [ChangeCharToTable]('1,2,3')

posted @ 2012-05-25 13:30  s80895304  阅读(175)  评论(0编辑  收藏  举报