Insert table select rows

  • Hi,

    I would like to avoid to user sql cursor for insert data from table to table

    I created this store procedure :

    CREATE

    PROCEDURE [contact].[importContactClient]

    @userid int, @id uniqueidentifier AS

    INSERT

    contactClient SELECT @userid, name, phoneNumber, adresse  FROM contactSupplier WHERE contactID = @id

    GO

    But I have this error : Must declare the scalar variable "@userID".


    Kindest Regards,

    degrem_m
    Degremont

  • You've put a variable in line 3, where you want a column name.

  • Basically, the procedure is OK. But how about some parentheses around it's parameters?

    CREATE PROCEDURE [contact].[importContactClient]

    (@userID int, @id uniqueidentifier) AS ...


    _/_/_/ paramind _/_/_/

  • When I add parentheses, it's the same error.

    @userid is variable. This value must be inserted foreach rows.

    CREATE PROCEDURE [contact].[importContactClient]

    (@userID int, @id uniqueidentifier AS)

    INSERT contactClient SELECT @userid, name, phoneNumber, adresse  FROM contactSupplier WHERE contactID = @id

    GO


    Kindest Regards,

    degrem_m
    Degremont

  • Hello,

    it's ok, I found.

    @userid didn't same type between this two table. (uniqueidentifier and int).

     


    Kindest Regards,

    degrem_m
    Degremont

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

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