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


    --第一种方式
    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

    sql 判断临时表是否存在,删除临时表重建

    IF Object_id('Tempdb..#dl'IS NOT NULL 
    DROP TABLE #dl --如果有存在就删除临时表
    CREATE TABLE #dl (neirong char(20),icount int, dlzonjine int, dlshu int, dlyin int--重建临时表
    INSERT INTO #dl SELECT FROM tab1 --把物理表的数据插到临时表

    --正确的临时表删除操作
    if object_id('tempdb..#tempTable') is not null Begin
        drop table #tempTable
    End

  • 相关阅读:
    CF div2 332 A
    vector resize 错误用法
    linux命令之 chown
    dlmalloc 编译 链接
    C++ 类 访问限制
    C++ 编译多态 运行多态
    libevent 编译 Windows
    浮点数小记
    NYOJ 435 棋盘覆盖(二)
    HDU 3555 Bomb 简单数位DP
  • 原文地址:https://www.cnblogs.com/skyay/p/12558316.html
Copyright © 2020-2023  润新知