VistaDB 5
Table Variable Example
Tables as a variable live only for the life of the single execution syntax and are automatically cleaned up. There is no need to drop this type of table.
Table Variable Example
Copy Code
PRINT 'Test Table Variable';

DECLARE @CustomersTemp TABLE (
ID int,
CustomerName varchar(30),
City varchar(50),
State varchar(50)
);

INSERT INTO @CustomersTemp (ID, CustomerName, City, State)
SELECT    *
FROM    customers
WHERE    state = 'florida';

declare @tvprows int;

set @tvprows = select count(id) from @CustomersTemp;

print 'Table variable contains:';
print @tvprows;

-- No need to drop the temp table here because it is a table variable
-- It will be cleaned up in scope
-- drop table @customertemp;
See Also