Okay, I've got what is probably a very easy question for you Sql gurus out there...
Given a boolean of some kind, T, I want to populate a temp table with data set A, if T is true, or data set B, if T is false. I thought this would be how to do it:
DECLARE @foo INT
SET @foo = null
IF (@foo is null)
BEGIN
SELECT 'foo was null' INTO #TempTable
END
ELSE
BEGIN
SELECT 'foo not null' INTO #TempTable
END
But this doesn't work. I get an error that reads "There is already an object named '#TempTable' in the database."
Apparently Sql is trying to create the table in each case, before it evaluates the condition...? That seems odd to me, but okay... But what's the proper way to do something like this?
Edit: I'm in Sql Server, but I suspect that this is a more universal issue...but if I'm wrong, please let me know.