Return to Snippet

Revision: 65846
at January 29, 2014 02:44 by ironcrema


Initial Code
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

Initial URL

                                

Initial Description
Función sql que devuelve una tabla. parametros ID, cadena, caracter_slit

Initial Title
Split SQL Server

Initial Tags
sql, server

Initial Language
SQL