Insert comma delimited values in table

  • @id = 1,2,3,4,5

    @name = 'NY, NJ, VA, DC,CA'

    I have a temp table called #tmp (id int, name varchar(4))

    I want to insert these above comma delimited values in this temp table.

    So 1 has corresponding value = NY, 2 has NJ etc...so total 5 rows will be inserted.

    Can u tell me the best way to code that?

  • Yes, change to use Table-Valued Parameters instead of passing in a comma-delimited list of values in a single parameter.

    Table-Valued Parameters (Database Engine) - SQL Server 2008 R2

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • If you can NOT use the suggestion of opc.three

    Read the following article by Jeff Moden:

    http://www.sqlservercentral.com/articles/Tally+Table/72993/

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

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

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