博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

sql server创建临时表的两种写法和删除临时表

Posted on 2021-06-16 11:47  sky410  阅读(189)  评论(0编辑  收藏  举报

--第一种方式

create table #tmp(name varchar(255),id int)
 
--第二种方式
select count(id) as storyNum ,
sum(convert(numeric(10,2),case when 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 end)) as realcodeNum,
tdtname,cycle,jiracomponent,jirastatename,qualityvalue,storycodellt
into #tmp from IKNOW_STORY_U2000V1R7C00 group by tdtname,cycle,jiracomponent,jirastatename,qualityvalue,storycodellt
 
--查询临时表
select * from #tmp
 
--删除临时表
if object_id('tempdb..#tmp') is not null
    begin
        drop table #tmp
    end