Monday, January 6, 2020

Function to Split comma separated string into rows


CREATE FUNCTION dbo.SplitTextToRows (@StringWithComma   varchar(1000))

RETURNS   @Result TABLE (Column1   VARCHAR(100))

AS

BEGIN

        DECLARE @IntLocation INT

        WHILE (CHARINDEX(',',    @ StringWithComma , 0) > 0)

        BEGIN

              SET @IntLocation =   CHARINDEX(',',    @ StringWithComma , 0)     

              INSERT INTO   @Result (Column1)

              --LTRIM and RTRIM to ensure blank spaces are   removed

              SELECT RTRIM(LTRIM(SUBSTRING(@StringWithComma   ,   0, @IntLocation)))  

              SET @ StringWithComma   = STUFF(@StringWithComma ,   1, @IntLocation,   '')

        END

        INSERT INTO   @Result (Column1)

        SELECT RTRIM(LTRIM(@StringWithComma   ))

        RETURN

END

GO



SELECT * FROM dbo. SplitTextToRows (India   ,  US,    Canada')

No comments:

Post a Comment

Activating All triggers in ADF using powershell

Scenario: I have an ADF having more than one pipelines. For each pipeline more than one triggers. I need to activate all the triggers i...