How to Pass Multiple values to single to single parameter

  • I have one requirement ,assign multiple values to single parameter to inset data.

    select * from emp(employee table)

    select * From test

    Create proc inserttest(@Idno int)

    as

    begin

    insert into test(id) values(@Idno)

    end

    declare @empno int

    select @empno= empno from emp

    exec inserttest @Idno=@empno

    Only one record was inserted in test table while executing this procedure.

    Q:I want to insert all the data in single execution.Could you please let me know how to insert.

  • First option, use a table valued parameter. Here's documentation on how that works.

    Another option, use Jeff Moden's scripts to turn comma delimited lists into a table. Here's documentation[/url] on that.

    "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

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

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