Creating a SQL table variable in a stored procedure

user5164496 picture user5164496 · Jul 28, 2015 · Viewed 33.3k times · Source

I want to create SQL variable table in stored procedure which include this;

Select a,b,c,d from **@tablename** where a=1 and c=0

How can do this with sp when creating sp?

Answer

Hari Chaudhary picture Hari Chaudhary · Jul 28, 2015

You can declare table variable in SP as:

DECLARE @tablename TABLE(
    a INT,
    b INT,
    c INT,
    d INT);

SELECT * FROM @tablename;