Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Conditionally create a temp table with IF...ELSE
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Conditionally create a temp table with IF...ELSE
Divers
Thread ID:
00869123
Message ID:
00869123
Vues:
53
I am creating a temp table inside a store proc. Depending on whether an input
parameter was passed, I run different code to create the temp table.

The SQL compiler gives me this error when I try to run the code:
There is already an object named #SelectedCustomers in the database.

What am I doing wrong here?

(This is a simplification of what I'm really working with)

-- @tcState is an input parameter to the stored proc, and is in scope.
IF @tcState IS NOT NULL BEGIN
SELECT kCustomer
INTO #SelectedCustomers
FROM Customers
WHERE cState = @tcState
END
ELSE BEGIN
SELECT kCustomer
INTO #SelectedCustomers
FROM Customers
END
"Problems cannot be solved at the same level of awareness that created them." - Albert Einstein

Bruce Allen
NTX Data
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform