create FUNCTION [dbo].[SM_SPLIT](
@delimited NVARCHAR(MAX),
@delimiter NVARCHAR(100)
) RETURNS @table TABLE (id INT IDENTITY(1,1), [value] NVARCHAR(MAX))
AS
BEGIN
DECLARE @xml XML
SET @xml = N'<t>' + REPLACE(@delimited,@delimiter,'</t><t>') + '</t>'
INSERT INTO @table([value])
SELECT r.value('.','Nvarchar(MAX)') as item
FROM @xml.nodes('/t') as records(r)
RETURN
END
@delimited NVARCHAR(MAX),
@delimiter NVARCHAR(100)
) RETURNS @table TABLE (id INT IDENTITY(1,1), [value] NVARCHAR(MAX))
AS
BEGIN
DECLARE @xml XML
SET @xml = N'<t>' + REPLACE(@delimited,@delimiter,'</t><t>') + '</t>'
INSERT INTO @table([value])
SELECT r.value('.','Nvarchar(MAX)') as item
FROM @xml.nodes('/t') as records(r)
RETURN
END
select * from dbo.SM_SPLIT(REPLACE('0, 111, 121, 131, 141, 211, 221, 231, 241, 251, 261, 271, 281, 212, 222, 232, 242, 252, 262, 272',' ',''),',')
No comments:
Post a Comment