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; |