Dynamic Query

  • Hi,

    I've the following dynamic SQL stmt.

    SET @strSQL = N'SET @RSCCount=Select Count(*) From tblRepNK'

    Where @RSCCount is an output parameter in a stored procedure. How do i execute it using sp_executesql @strSQL .

     

    TIA

  • EXEC('sp_executesql ' + @strSQL)

    Hope this works


    Kindest Regards,

    Charles Wilkinson
    Database Administrator
    Sastek Pty Ltd
    www.sastek.com

  • Sorry it still does not work. I hope you understood the problem. I want no. of rows returned by count(*) in the @RSCCount output parameter.

    Thanks for your time.

  • EXEC('sp_executesql ' + @strSQL) will set the value of @RSC

    add this line

    print @RSC

  • DECLARE @LiveRowCount BIGINT,

            @SqlCmd NVARCHAR(4000)

    SET @SqlCmd = 'SELECT @RowCount = COUNT(*) FROM ' + QUOTENAME(@MyTableName)

    EXEC sp_executesql @SqlCmd, N'@RowCount BIGINT OUT', @LiveRowCount OUT

    IF @LiveRowCount > 0

            PRINT 'Row count = ' + CAST(@LiveRowCount AS VARCHAR)

    Hope this helps

    Wayne

     

  • Hi Wayne,

    U R Awesome.

    Thanks a lot for your time.

     

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

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