--Create, delete temporary tables
--The first way
create TABLE #tmp (name varchar (255), id int)-
-The second way
select COUNT (id) as Storynum,
sum (convert (Numeric (10,2), Case if IsNumeric (code) =1 then code else 0 end)) As Codenum,
sum ((Case when IsNumeric (realcode) =1 then convert (numeric (10,2), realcode) else 0.0)) as Realcodenum,
tdtname,cycle,jiracomponent,jirastatename,qualityvalue,storycodellt into
#tmp from Iknow_story_ U2000V1R7C00 GROUP BY Tdtname,cycle,jiracomponent,jirastatename,qualityvalue,storycodellt
-Query temp table
SELECT * From #tmp-
-Deletes temporary table
if object_id (' tempdb ... #tmp ') is not null
begin
DROP table #tmp
Correct deletion of SQL Server temp table
Deleting a SQL Server temporary table is not the same as a generic table, and the following will be a sample error for you and the correct deletion for your reference, in the hope of helping you.
A temporary table differs from a regular table in that it is saved to the tempdb table. The table name of the temporary table is not the same as the name of the table you built, because he wants to create a different temporary table for the same action for different people.
1, the wrong delete operation:
--incorrect temporary table deletion because the database is different
IF EXISTS (SELECT * from sysobjects where object_id = object_id (N ' [dbo].[ #tempTable] ') and type in (N ' U '))
Begin
DROP TABLE [dbo].[ TempTable]
End
-the wrong temporary table deletion operation because the temporary table name has been changed
if exists (SELECT * from tempdb.dbo.sysobjects where id = object_id (N ' [#temptable])
Begin
drop table #temptable End
2, the correct way to delete:
--The correct temporary table deletion operation
if object_id (' tempdb ... #tempTable ') is isn't null Begin
drop table #tempTable
end
SQL to determine if temporary table exists, delete temporary table rebuild
IF object_id (' Tempdb.. #dl ') is a not NULL
DROP table #dl--Deletes the temporary table
CREATE table #dl (Neirong char (), icount int, Dlzonjine int, DLS Hu int, Dlyin int)--Reconstructing temporary table
INSERT into #dl SELECT * tab1-inserting data from physical tables into temporary tables