declaring an existing table for selects sql server code example
Example 1: sql declare table variable
DECLARE @TABLE TABLE( COL1 INT, COL2 VARCHAR(30))
Example 2: select into table variable
DECLARE @userData TABLE(
name varchar(30) NOT NULL,
oldlocation varchar(30) NOT NULL
);
INSERT INTO @userData (name, oldlocation)
SELECT name, location FROM myTable
INNER JOIN otherTable ON ...
WHERE age > 30;