sp_executesql giving error inside stored procedure

  • Hi All,

    I have created a dynamic statement using sp_executesql but i am getting below error on execution.

    Error:

    Could not find stored procedure 'SELECT @TDATA=COUNT(*) FROM TBL_Q6310'.

    Statement inside stored procedure

    SET @SQLString = N'SELECT @TDATA=COUNT(*) FROM '+@QName

    EXEC dbo.sp_executesql

    @query = @SQLString,

    @params = N'@TDATA INT OUTPUT',

    @TDATA = @TDATA OUTPUT

    Please guide me how can i resolve this issue.

    Thanks!

    Shatrughna

    Shatrughna

  • Try this

    DECLARE @SQLString nvarchar(500);

    DECLARE @ParmDefinition nvarchar(500);

    DECLARE @TDATA varchar(30);

    declare @QName varchar(50)='TBL_Q6310'

    SET @SQLString = N'SELECT @TDATAOUT = Count(*) FROM '+@QName

    SET @ParmDefinition = N' @TDATAOUT varchar(30) OUTPUT';

    print @SQLString

    print @ParmDefinition

    EXECUTE sp_executesql @SQLString, @ParmDefinition, @TDATAOUT=@TDATA OUTPUT;

    SELECT @TDATA;

    Thanks
    Parthi

  • Thanks Parthi for your valuable effort.

    I got the solution.

    Thanks!

    Shatrughna

    Shatrughna

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

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