Extract csv values with multiple rows?

  • hi friend,

    i have the following csv value sent from the client:

    @csv nvarchar(max)

    set @csv

    =

    1,'hello, how are you?',23.44,f,1,'sfsfsdfssfs'

    2,'c, d and q are not',2.34,t,1,'sdfss'

    3,'c, e and a are not',34.8,f,1,'sdfss'

    4,'i, j and k are not',5.77,f,1,'sdfss'

    Note that the valeu in @csv is a multi line and multi columned. How do i extract these values

    and store in temp table or return as a table from table-valeu fucntion?

    PS: im SQL learner so please, commment and explain the SQL statements that you write 🙂

    thank you

  • Tel me, your client is giving all the data in a single variable ? i mean, all the rows combined into a variable ?

    Some more Qs:

    1. Will rows be separated by an "Enter" (or line-feed) inside the variable, always ?

    2. Is the number of comma separated values consistent in the local variable for each row?

  • ColdCoffee (9/30/2010)


    Tel me, your client is giving all the data in a single variable ? i mean, all the rows combined into a variable ?

    Yes

    Some more Qs:

    1. Will rows be separated by an "Enter" (or line-feed) inside the variable, always ?

    each line was seperated by a "new line charactor" or in C#

    2. Is the number of comma separated values consistent in the local variable for each row?

    Yes, as you can see in structure of the values in my original post : )

  • Please see the following to do what you need...

    http://www.sqlservercentral.com/articles/T-SQL/63003/

    The embedded comma that you have will cause a bit of frustration on your part but I'm sure you'll be able to work around that.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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