zoukankan      html  css  js  c++  java
  • 使用临时表的存储过程

    下面是一个使用临时表的存储过程例子

    USE [JointFrame31_zw]
    GO
    /****** Object:  StoredProcedure [dbo].[Proc_ZL_GetMonthFlow]    Script Date: 2017/04/05 9:18:29 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:        <水狼一族>
    -- Create date: <2017.04.05>
    -- Description:    <查看全市污染物各月份的排放量情况>
    -- TSQL: Proc_ZL_GetMonthFlow 
    -- =============================================
    
    ALTER PROCEDURE [dbo].[Proc_ZL_GetMonthFlow]
    
    AS
    SET NOCOUNT ON 
    begin
    --创建废水临时表
        create table #w(MonitorDate varchar(6),CODFlow numeric(18,6),NH4Flow numeric(18,6))
     --插入废水临时表
        insert into #w
        exec [AutoMonitor].[dbo].Proc_Big_Get_Pollutant_Month_Data_Water
    --创建废气临时表
        create table #g(
        MonitorDate varchar(6),
        YCFlow numeric(18,4),
        S02Flow numeric(18,4),
        NOXFlow numeric(18,4)
        )
     --创建废气临时表
        insert into #g
        exec [AutoMonitor].[dbo]. Proc_Big_Get_Pollutant_Month_Data_Gas
    
        select MonitorDate into #date from #w a union select b.MonitorDate from #g b
    
        select p.*,isnull(CODFlow,0) CODPercent,isnull(NH4Flow,0) NH4Percent,isnull(YCFlow,0) YCPercent,
        isnull(S02Flow,0) S02Percent,isnull(NOXFlow,0) NOXPercent
         from #date p left join #w a on p.MonitorDate = a.MonitorDate
        left join #g b on p.MonitorDate = b.MonitorDate
    
        truncate table #w
        drop table #w
    
        truncate table #g
        drop table #g
    
        truncate table #date
        drop table #date
    
    end
  • 相关阅读:
    MySQL的max()函数使用时遇到的小问题
    scp命令需要指定端口时要紧跟在scp后
    linux系统之间基于密钥对免输入密码登陆
    c++的引用用法
    预测模型
    mysql出现ERROR 1366 (HY000):的解决办法
    R语言可视化--颜色
    R语言可视化--ggplot函数
    R语言可视化--qplot函数
    R语言可视化二
  • 原文地址:https://www.cnblogs.com/shuilangyizu/p/6669573.html
Copyright © 2011-2022 走看看