TSQL convertir CSV en table
CREATE FUNCTION [dbo].[CSV2TABLE] (@InStr nvarchar(MAX))
RETURNS @TempTab TABLE
(id nvarchar(MAX) NOT NULL)
AS
BEGIN
SET @InStr = REPLACE(@InStr + ',', ',,', ',')
DECLARE @SP INT
DECLARE @VALUE nvarchar(MAX)
WHILE PATINDEX('%,%', @INSTR ) <> 0
BEGIN
SELECT @SP = PATINDEX('%,%',@INSTR)
SELECT @VALUE = LEFT(@INSTR , @SP - 1)
SELECT @INSTR = STUFF(@INSTR, 1, @SP, '')
INSERT INTO @TempTab(id) VALUES (@VALUE)
END
RETURN
END
BlackSwan