Insert multiple columns

  • Hi all,

    I need to insert one row in table.but it has more than 35 columns.

    I have datatable it has all the columns with value(only one row)

    so is there any way to pass the whole datatable to db without specifying columns and without use bulk copy(because datatable has only one row)

  • Like this?

    INSERT INTO x

    (

    ...

    )

    SELECT ...

    FROM y

    ... = column names 😀

  • With only a single row to send, I'd suggest just creating a procedure or parameterized query that lists the columns and send that over. That really is the better approach. Absolutely.

    However, if you want to, you can use table-valued parameters. It's outlined here.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thank you very much.

    I get inserted successfully through the method which u specify

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

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