Showing posts from August, 2017Show All

Can we use Temp Table and Table Variable in Dynamic scripts?

 You can use a table variable with dynamic SQL, but you must declare the table inside the dynamic SQL itself. The following query will fail with the error “Must declare the variable '@MyTable'.”

DECLARE @MyTable TABLE
(
  ProductID int ,
  Name varchar(10)
)
 
 
EXEC sp_executesql N'SELECT * FROM @MyTable'

Dynamic SQL vs Stored Procedure

exec vs sp_executesql in sql server

What is Dynamic SQL