我正在尝试以下查询
if exists (select 1 from emp where eid = 6)
begin
if object_id('tempdb..#columntable') is not null
begin
drop table #columntable
end
create table #columntable (oldcolumns varchar(100))
end
else
begin
if object_id('tempdb..#columntable') is not null
begin
drop table #columntable
end
create table #columntable (newcolumns varchar(100))
end
Run Code Online (Sandbox Code Playgroud)
但是我收到了错误
Msg 2714, Level 16, State 1, Line 8
There is already an object named '#columntable' in the database.
Run Code Online (Sandbox Code Playgroud)
谁有人建议为什么?如果我不写else部分,相同的查询工作正常.