Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating temporary table
Message
 
 
À
04/02/2014 13:59:29
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01593184
Message ID:
01593185
Vues:
61
This message has been marked as the solution to the initial question of the thread.
>Here is an example of a command to create a temporary table:
>
>
>SELECT Numero INTO #Temp FROM Country WHERE Country.Numero<10
>
>
>That will create #Temp with 9 records.
>
>If I try to do this again, I have:
>
>"There is already an object named '#Temp' in the database."
>
>However, this does not exist in the database. This is memory only.
>
>So, for as long as I remain in the same window, I cannot do it. But, if I open another query window, I can do this command again.
>
>What kind of cleanup is necessary so I can execute the same command?
IF OBJECT_ID('TempDB..#Temp', N'U') IS NOT NULL DROP TABLE #Temp;

select numero into #Temp from dbo.Country where Country.Numero < 10;
The first check with object_id will verify if the table already exists or not and will drop it if it exists.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform