使用临时表的存储过程

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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值