5

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?

Kev
  • 15,899
  • 15
  • 79
  • 112

2 Answers2

8

You can declare table variable in SP as:

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

SELECT * FROM @tablename;
Hari Chaudhary
  • 630
  • 1
  • 7
  • 20
0

I hope this answer helps you

GO
CREATE PROCEDURE PrededureName
AS
BEGIN
DECLARE @tempTable TABLE
(
    a INT, 
    b INT,
    c INT,
    d INT
)
INSERT INTO @tempTable (a, b, c, d)
SELECT a, b, c, d FROM @tablename WHERE a=1 and c=0
END
GO;
Ahmad Al ALloush
  • 330
  • 3
  • 10