Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/08/2007, 10:58
Avatar de Mithrandir
Mithrandir
Colaborador
 
Fecha de Ingreso: abril-2003
Mensajes: 12.106
Antigüedad: 21 años
Puntos: 25
Re: array en cursor

No existe una función hecha que logre lo que buscas, pero te paso uno de mis códigos. Lo obtuve de sqlservercentral.com y después lo ajusté a mis necesidades (por aquello del reconocimiento a quien verdaderamente lo hizo).

En este caso el separador es la '@', reemplazala por la ',' que es tu caso y prueba el resultado.

Código:
CREATE FUNCTION dbo.fnStringListToTable (@stringlist ntext)
RETURNS @tbl TABLE (
	row_no		int IDENTITY(1, 1) NOT NULL,
	number_int	int NOT NULL,
	number_decimal	decimal(15,5),
	string		nvarchar(100) NOT NULL
) AS

/*
fnStringListToTable		Rodrigo Guerra		2005-04-26

Regresa una tabla en memoria a partir de la cadena separada por
espacios que se pasa como parametro.
*/

BEGIN
	DECLARE @pos	int,
		@textpos	int,
		@chunklen	smallint,
		@int_val 	int,
		@dec_val	decimal(15,5),
		@str_val	nvarchar(4000),
		@tmpstr		nvarchar(4000),
		@leftover	nvarchar(4000)
	
	SET @textpos = 1
	SET @leftover = ''
	
	WHILE @textpos <= datalength(@stringlist) / 2
	BEGIN
		SET @chunklen = 4000 - datalength(@leftover) / 2
		SET @tmpstr = ltrim(@leftover + substring(@stringlist, @textpos, @chunklen))
		SET @textpos = @textpos + @chunklen
	
		SET @pos = charindex('@', @tmpstr)		--"@" es el separador de cadena
		WHILE @pos > 0
		BEGIN
			SET @str_val = substring(@tmpstr, 1, @pos - 1)
			SET @int_val = CASE WHEN dbo.fnIsNumeric(@str_val) = 1 THEN CONVERT(int, CONVERT(float, @str_val)) ELSE 0 END
			SET @dec_val = CASE WHEN dbo.fnIsNumeric(@str_val) = 1 THEN CONVERT(decimal(15,5), @str_val) ELSE 0 END
			INSERT @tbl (number_int, number_decimal, string) VALUES(@int_val, @dec_val, @str_val)
			SET @tmpstr = ltrim(substring(@tmpstr, @pos + 1, len(@tmpstr)))
			SET @pos = charindex('@', @tmpstr)
		END
	
		SET @leftover = @tmpstr
	END
	
	IF ltrim(rtrim(@leftover)) <> ''
		INSERT @tbl (number_int, number_decimal) VALUES(convert(int, @leftover), convert(decimal(15,5), @leftover))
	
	RETURN

END
__________________
"El hombre, en su orgullo, creó a Dios a su imagen y semejanza."
Friedrich Nietzsche