Split String

  • DECLARE @Sname CHAR(11) = 'A,B,C,D,E,F'

    SELECT

    split = SUBSTRING(@Sname, position.i, 1)

    FROM (VALUES (1), (3), (5), (7), (9), (11)) AS position (i)

  • How to split the following string ?

    Note: Without using split function,dynamic sql and xml

    Declare @Sname Varchar(Max)

    Set @Sname='A,B,C,D,E,F'

  • thanks and the following string will not work for yours solution

    Declare @Sname Varchar(255)

    set @Sname='SQL SERVER,ORACLE,MYSQL'

    Need query urgent

  • satishthota (11/6/2011)


    thanks and the following string will not work for yours solution

    Declare @Sname Varchar(255)

    set @Sname='SQL SERVER,ORACLE,MYSQL'

    Need query urgent

    DECLARE @sname VARCHAR(255) = 'SQL SERVER,ORACLE,MYSQL';

    SELECT

    SUBSTRING(@sname, N.n, CHARINDEX(string.comma, string.csv, N.n + 1) - N.n - 1)

    FROM

    (

    SELECT

    v.number

    FROM master.dbo.spt_values AS v

    WHERE

    v.[type] = N'P'

    AND v.number BETWEEN 1 AND DATALENGTH(@sname)

    ) AS N (n)

    CROSS APPLY

    (

    VALUES (CHAR(44), CHAR(44) + @sname + CHAR(44))

    ) AS string (comma, csv)

    WHERE

    SUBSTRING(string.csv, N.n, 1) = string.comma

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply