if @condition = '1'
begin
declare @tmptable1 table (col1 int,col2 int)
end
else
begin
declare @tmptable1 table (col1 int,col2 int, col3 int, col4 int)
end
出現以下錯誤
Msg 134, Level 15, State 1, Line 13
The variable name '@tmptable1' has already been declared. Variable names must be unique within a query batch or stored procedure.
改成用temp table 也不行
if @condition = '1'
begin
create table #tmptable1 (col1 int,col2 int)
end
else
begin
create table #tmptable1 (col1 int,col2 int, col3 int, col4 int)
end 出現以下錯誤
Msg 2714, Level 16, State 1, Line 15
There is already an object named '#tmptable1' in the database.
最後折衷好了...馬是口以啦...
create table #tmptable1 (col1 int,col2 int, col3 int, col4 int)
if @condition = '1'
begin
alter table #tmptable1
drop column col3,col4
drop column col3,col4
end
沒有留言:
張貼留言