I am trying to populate a temporary table based on the result of a condition in SQL 2005. The temporary table will have the same structure anyway, but will be populated using a different query depending on the condition. The following is a simplified script example in parsing an ELSE INSERT INTO block with an error:
An object already exists with the name '#MyTestTable' in the database.
DECLARE @Id int SET @Id = 1 IF OBJECT_ID('tempdb..#MyTestTable') IS NOT NULL DROP TABLE
I can create a temporary table before the IF/ELSE and then just make the INSERT SELECT in conditional blocks, but there will be many columns in the table, and I tried to be efficient. Is this the only option? Or is there a way to make this work?
Thanks Matt
sql sql-server-2005 temp-tables insert-into
Cuppm
source share