CREATE FUNCTION [dbo].[SPLIT] (@LIST VARCHAR(1000), @SPLIT_BY VARCHAR(1)=',')
RETURNS TABLE
WITH SCHEMABINDING
AS
RETURN
(
SELECT ROW_NO=row_number()over(order by @@rowcount),ITEM = y.i.value('(./text())[1]', 'nvarchar(50)')
FROM
(
SELECT x = CONVERT(XML, '<i>'
+ REPLACE(@List, @SPLIT_BY, '</i><i>')
+ '</i>').query('.')
) AS a CROSS APPLY x.nodes('i') AS y(i)
);
No comments:
Post a Comment