zoukankan      html  css  js  c++  java
  • 【Vegas原创】经典的用于报表的Procedure

        因报表经常计算百分比之类的,但平常的SQL查询比较慢,适合使用Procedure以优化程序。

    ---Vegas Created 2007/10/16

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go

    ALTER PROCEDURE [dbo].[pms_potential_Chart]
    @i int ,           --potential
    @j nvarchar(50),   --dept
    @year nvarchar(50),  
    @pa nvarchar(50)
    as

    declare @a int
    declare @b int
    declare @name nvarchar(50)
    declare @month int


    if @year='-1'   ----year
    begin
     
    select @year=substring(CONVERT(varchargetdate(), 120 ),1,4
    end 

    if @pa='-1'    -----pa
    begin 
     
    select @month=month(getdate())
    if @month<6
    begin
    set @pa='1'
    end
    else 
     
    begin
    set @pa='2'
    end
    end

    if @i=1         ----potential
    begin
    set @name='HPP'
    end 
    else if @i=2
    begin 
    set @name='VP'
    end
    else if @i=3
    begin
    set @name='BCP'
    end


    if @j='all'           ---dept
    begin 
    select @a=count(distinct part2.workid) from part2,members where  members.workid=part2.workid and part2.potential=@i and part2.year=@year and part2.pa_type=@pa
    select @b=count(distinct part2.workid) from part2,members where potential is not null and potential<>0 and members.workid=part2.workid and part2.year=@year and part2.pa_type=@pa
    select @name,@a/@b*1.0
    end

    else 
    if @j='DTS' or @j='DTM'
    begin 
    select @a=count(distinct part2.workid) from part2,members where  members.workid=part2.workid and members.dept_id like @j and part2.potential=@i  and part2.year=@year and part2.pa_type=@pa
    select @b=count(distinct part2.workid) from part2,members where potential is not null and potential<>0 and members.workid=part2.workid and members.dept_id= @j  and part2.year=@year and part2.pa_type=@pa
    select @name,@a/@b*1.0
    end
    else 
    begin 
    select @a=count(distinct part2.workid) from part2,members where  members.workid=part2.workid and members.dept_id like @j and part2.potential=@i and part2.year=@year and part2.pa_type=@pa
    select @b=count(distinct part2.workid) from part2,members where potential is not null and potential<>0 and members.workid=part2.workid and members.dept_id like @j+'___' and part2.year=@year and part2.pa_type=@pa
    select @name,@a/@b*1.0
    end


  • 相关阅读:
    Codeforces 1491 D. Zookeeper and The Infinite Zoo (二进制处理)
    Codeforces 1479A. Searching Local Minimum(注意输入+二分)
    Codeforces 1480B. The Great Hero(阅读模拟题,注意数据范围和攻击顺序)
    Codeforces 1480A. Yet Another String Game (阅读理解题)
    windows 10 开启全盘瞬间索引功能
    JetBrains CLion C++ IDE连接wsl2(Ubuntu)时,报错"Unable to establish SSL connection"解决方案
    WorkFlowy 的 MarkDown 预览方案解决
    git 学习 完全学懂
    jeecgboot <j-popup
    面试之类加载器
  • 原文地址:https://www.cnblogs.com/amadeuslee/p/3744625.html
Copyright © 2011-2022 走看看