Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Creating temporary table
Message
 
 
To
04/02/2014 13:59:29
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01593184
Message ID:
01593185
Views:
62
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform