/ Published in: SQL
Función sql que devuelve una tabla. parametros ID, cadena, caracter_slit
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[Split] ( @ID INT, @RowData nvarchar(MAX), @SplitOn nvarchar(5) ) RETURNS @ReturnValue TABLE (ID INT, DATA NVARCHAR(MAX)) AS BEGIN DECLARE @Counter INT SET @Counter = 1 While (Charindex(@SplitOn,@RowData)>0) BEGIN INSERT INTO @ReturnValue (ID, DATA) SELECT ID = @ID, DATA = ltrim(rtrim(SUBSTRING(@RowData,1,Charindex(@SplitOn,@RowData)-1))) SET @RowData = SUBSTRING(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData)) SET @Counter = @Counter + 1 END INSERT INTO @ReturnValue (ID, DATA) SELECT ID=@ID, DATA = ltrim(rtrim(@RowData)) RETURN END