sp_executesql

  • I need a fresh set of eyes can anyone tell me what is wrong with this script:

    DECLARE @SQLString nvarchar(50);

    DECLARE @ParmDefinition nvarchar(100);

    DECLARE @Trig_ID_Out VARCHAR(10);

    SET @SQLString = N'spiTriggerControl';

    SET @ParmDefinition = N'@Trig_ID VARCHAR(10) OUTPUT';

    EXECUTE sp_executesql @SQLString, @ParmDefinition, @Trig_ID=@Trig_ID_Out OUTPUT;

    SELECT @Trig_ID_Out

    I am getting the following syntax error:

    Msg 102, Level 15, State 1, Line 1

    Incorrect syntax near 'spiTriggerControl'.

    Thanks,

  • I think you need this:

    SET @SQLString = N'spiTriggerControl';

    to be this:

    SET @SQLString = N'Exec spiTriggerControl';

    I'm not sure why you are using sp_executesql based on the information you have provided. You could just do:

    DECLARE @Trig_ID_Out VARCHAR(10);

    Exec spiTriggerControl @Trig_ID_Out OUTPUT;

    SELECT @Trig_ID_Out

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

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