IF OBJECT_ID('fnSplit') IS NOT NULL
DROP FUNCTION fnSplit
GO
CREATE FUNCTION dbo.fnSplit(
@sInputList VARCHAR(8000)
, @sDelimiter VARCHAR(8000) = ','
) RETURNS @List TABLE (item VARCHAR(8000))
/* Fecha creacion : 07/05/2012
Elabor�: Marco Polo Flores
Comentario: Función para regresar listado en forma de tabla
USO SELECT * FROM dbo.fnSplit('a,b',',')
*/
BEGIN
DECLARE @sItem VARCHAR(8000)
WHILE CHARINDEX(@sDelimiter,@sInputList,0) <> 0
BEGIN
SELECT
@sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@sDelimiter,@sInputList,0)-1))),
@sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList))))
IF LEN(@sItem) > 0
INSERT INTO @List SELECT @sItem
END
IF LEN(@sInputList) > 0
INSERT INTO @List SELECT @sInputList
RETURN
END
GO
Regresa cadena string en forma de tabla....USO SELECT * FROM dbo.fnSplit('a,b',',')
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.