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')

你可能感兴趣的:(change)