Regarding inserting records into 2 tables at a time using stored procedure

  • Regards

  • Pardon me for asking, but why is this posted as a poll?



    Ole Kristian Velstadbråten Bangås - Virinco - Facebook - Twitter

    Concatenating Row Values in Transact-SQL[/url]

  • Well, you are missing the '@' for email parameter for the second insert.

    And I am not sure why @emailtable is defined in the procedure and you are using "select @emailaddress from emailtable". Did you want to elaborate?

    It seems to me you would just want to insert a single email address into two separate tables. If so, you would use the following:

    create procedure RS(@emailtable as nvarchar(255))

    as

    set nocount on

    begin

    insert into tri1(email)

    values (@emailaddress)

    insert into tri2(email)

    values (@emailaddress)

    go

    exec RS 'myemail@gmail.com'

  • nicko5 (11/3/2011)


    It seems to me you would just want to insert a single email address into two separate tables. If so, you would use the following:

    create procedure RS(@emailtable as nvarchar(255))

    as

    set nocount on

    begin

    insert into tri1(email)

    values (@emailaddress)

    insert into tri2(email)

    values (@emailaddress)

    go

    exec RS 'myemail@gmail.com'

    That would not work becqause you have called the parameter @emailtable in the proc header but used @emailaddress in the proc body.

    Tom

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

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