StephenLeach
Programmer
I have an IF statement whereby a tempory table is created by a SELECT INTO command. If the IF statement evaluates to true then the data for the temporary table comes from one source and if the IF statement is FALSE then the data comes from a second source. The name of the temporary table is the same regardless.
e.g.
IF @value = 0
BEGIN
SELECT * INTO #Temp FROM TableA
END
ELSE
BEGIN
SELECT * INTO #Temp FROM TableB
END
When I run this I get an error stating that the table #Temp already exists.
It is as if when doing a SELECT INTO, SQL ignores the IF. I have check the IF statement is valid by replacing the SELECT INTO's with SELECT 'Case A' and SELECT 'Case B'.
Does anyone have any ideas or come across similar problems?
e.g.
IF @value = 0
BEGIN
SELECT * INTO #Temp FROM TableA
END
ELSE
BEGIN
SELECT * INTO #Temp FROM TableB
END
When I run this I get an error stating that the table #Temp already exists.
It is as if when doing a SELECT INTO, SQL ignores the IF. I have check the IF statement is valid by replacing the SELECT INTO's with SELECT 'Case A' and SELECT 'Case B'.
Does anyone have any ideas or come across similar problems?