Temp table value problem

I created temp table like the below, select into the values, however, I got the error says"There is already an object named '##report' in the database.".  Please help

Create table ##report
(
OMSC# int,
Total_Received int,
Total_Action int,
Monthly varchar(10),
Percentage decimal
)
select *
into ##report
from Requests

March 23rd, 2015 3:05am

--Option.1 --> Use INSERT INTO if you already have created table in advance.
Create table ##report
(
OMSC# int,
Total_Received int,
Total_Action int,
Monthly varchar(10),
Percentage decimal
)

INSERT INTO ##report
SELECT * FROM Requests

-- Option.2 --> Directly create ##report temp table by using SEELCT INTO

SELECT *
INTO ##report
FROM Requests

Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 3:10am

In addition to Vaibhav's comment,##report is GLOBAL temp table (##), the scope is global. Hence, if other session is already created, then the current session tried to create it, it will show the error message. 

If you are looking for session scope temp table, you may use the below:(note that only one #)

Create table #report
(
OMSC# int,
Total_Received int,
Total_Action int,
Monthly varchar(10),
Percentage decimal
)
select *
into #report
from Requests

March 23rd, 2015 3:11am

I created temp table like the below, select into the values, however, I got the error says"There is already an object named '##report' in the database.".  Please help

Create table ##report
(
OMSC# int,
Total_Received int,
Total_Action int,
Monthly varchar(10),
Percentage decimal
)
select *
into ##report
from Requests

You need to choose one other temp table name instead.
Free Windows Admin Tool Kit Click here and download it now
March 23rd, 2015 3:36am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics