EXEC INSERT INTO TABLE with PARAMETER

  • Anyone can help me .

    Is it possible to do this ..

    DECLARE

    @ProjectCode varchar(25),

    @TypeCodevarchar(25),

    @BomDatevarchar(25),

    SET @ProjectCode='PRO000001'

    SET @TypeCode='PS0000001'

    EXEC ('

    INSERT INTO [dbo].[zPS-XSCN231L] (

    [level],

    [Pin],

    [Description]

    )

    VALUES (

    @ProjectCode,

    @TypeCode,

    @BomDate

    )

    ')

  • Not with EXEC, but you can use sp_executesql to execute strings with parameters.

    That said, there's absolutely no need for dynamic SQL in the code you posted. This is equivalent and works without any exec needed.

    DECLARE

    @ProjectCode varchar(25),

    @TypeCodevarchar(25),

    @BomDatevarchar(25),

    SET @ProjectCode='PRO000001'

    SET @TypeCode='PS0000001'

    INSERT INTO [dbo].[zPS-XSCN231L] (

    [level],

    [Pin],

    [Description]

    )

    VALUES (

    @ProjectCode,

    @TypeCode,

    @BomDate

    )

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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