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

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

 

相关文章:

  • 2021-12-27
  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2022-01-19
  • 2021-09-02
  • 2022-12-23
猜你喜欢
  • 2021-11-14
  • 2021-07-09
  • 2021-11-23
  • 2021-10-18
  • 2021-11-11
  • 2021-09-27
相关资源
相似解决方案