Skip to content
Advertisement

How to Run Two T-Sql Statement By Exec Command in SqlServer?

I want run 2 SQL queries in Exec instruction, how can I do this?

ListOfLeaveRemainingInfo is a user-defined table type:

When I run the stored procedure, I get this error:

Msg 1087, Level 15, State 2, Line 33
Must declare the table variable “@LeaveRemainingTempTable”

Advertisement

Answer

Scratch the previous.

@LeaveRemainingTempTable is a table variable. It therefore doesn’t exist within the scope of the dynamic SQL.

If dbo.listofleaveremaininginfo always has the same columns you can pass it in as a table variable:-

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement