I've been racking my brain but can't see what the problem is with the query below.
I've created a temporary table which can hold one of two values.
The idea is that if 1 is stored it executes the first part of the code below (This) and if it's 2 it executes the code further below (That).
Trouble is the code won't run because it "seems" to think that both parts of the code will be executed ... I think. Any ideas?
create table #Globals(G1 smallint);
insert into #Globals values (1); 
--insert into #Globals values (2); 
if (select G1 from #Globals) = 1
  select 'This' as field1 into #x;
else if (select G1 from #Globals) = 2
  select 'That' as field1 into #x;
Msg 2714, Level 16, State 1, Line 8
There is already an object named '#x' in the database.
 
     
    