Я пытаюсь выполнить следующий запрос
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
Но получаю сообщение об ошибке
Msg 2714, Level 16, State 1, Line 8
There is already an object named '#columntable' in the database.
Кто-нибудь может подсказать, почему? Тот же запрос работает нормально, если я не напишу часть else.