Here is my simple question: I want to declare a table variable with different columns according to the value of a predefined variable
The query is as below:
if (@a = 1)
begin
declare @table_1 table (
col1 int,
col2 int,
col3 int
)
end
else
begin
declare @table_1 table (
col1 int,
col3 int
)
end
But the error pump out saying "The variable name '@table_1' has already been declared. Variable names must be unique within a query batch or stored procedure"
Is there any way to do it?