Home Forums SQL Server 7,2000 T-SQL Problem with the text data column, variable RE: Problem with the text data column, variable

  • harsha.bhagat1 (8/29/2008)


    I have to receive a text field in which you cannot add any extra ',' anywhere .

    If you are receiving the data as a parameter why can't you declare a new variable to add the beginning and ending commas? Like this:

    Declare @text varchar(8000)

    Set @text = ',' + @parameter + ','

    Then you process the @text variable or you can just do this:

    Select

    Substring(',' + @text + ',', N+1, Charindex(',', ',' + @text + ',', N+1) - n -1)

    From

    tally

    Where

    N <= Len(',' + @text + ',') AND

    SUBSTRING(',' + @text + ',', N,1) = ',' And

    Charindex(',', ',' + @text + ',', N+1) > 0

    order by

    n