Skip to the content.

There are two kinds of SQL variables; scalar variables that hold a single typed value, and table-variables that work like temporary-tables, but with very specific scoping rules. You cannot treat a scalar variable like a table; you can’t insert into, update, delete from or select from a scalar variable:

Bad:

declare @id int = 0;
select * from @id;

Good:

declare @id int = 0;
select @id;