阳光网驿-企业信息化交流平台【DTC零售连锁全渠道解决方案】

 找回密码
 注册

QQ登录

只需一步,快速开始

扫描二维码登录本站

手机号码,快捷登录

老司机
查看: 1701|回复: 3

[原创] 查询本周,本月,本季度,本年的销售金额,带关键字的

[复制链接]
  • TA的每日心情
    奋斗
    前天 08:56
  • 签到天数: 1149 天

    [LV.10]以坛为家III

    发表于 2008-5-19 16:19:15 | 显示全部楼层 |阅读模式
    带参数的,存储过程,
    直接报表调用方法:exec up_xsje1 '########'
    '########' 是k3关键字,其他用法类似。
    /*
        功能描述:    查询本周,本月,本季度,本年的销售金额
    */
    CREATE procedure up_xsje1
                @mydate        datetime
    as
                declare        @thisWeek    datetime,
                        @thisMonth    datetime,
                        @thisQuarter    datetime,
                        @thisYear    datetime,
                        @nextWeek    datetime,
                        @nextMonth    datetime,
                        @nextQuarter    datetime,
                        @nextYear    datetime
            if( DATEADD(wk, DATEDIFF(wk,0,@mydate), 0) < @mydate)
            begin
                select        @thisWeek = DATEADD(wk, DATEDIFF(wk,0,@mydate), 0)            --本周的第一天
            end
            else
            begin
                select        @thisWeek = DATEADD(wk, DATEDIFF(wk,0,@mydate), 0) - 7        --本周的第一天
            end
                select        @thisMonth = DATEADD(mm, DATEDIFF(mm,0,@mydate), 0)              --本月的第一天
                select        @thisQuarter = DATEADD(qq, DATEDIFF(qq,0,@mydate), 0)         --本季度的第一天
                select        @thisYear = DATEADD(yy, DATEDIFF(yy,0,@mydate), 0)              --本年的第一天

            if( DATEADD(wk, DATEDIFF(wk,0,@mydate), 0) < @mydate)
            begin
                select        @nextWeek = DATEADD(wk, DATEDIFF(wk,0,(@mydate + 7)), 0)         --下周的第一天
            end
            else
            begin
                select        @nextWeek = DATEADD(wk, DATEDIFF(wk,0,@mydate), 0)             --下周的第一天
            
            end
                select        @nextMonth = DATEADD(mm, DATEDIFF(mm,0,(@mydate + 31)), 0)          --下月的第一天
                select        @nextQuarter = DATEADD(qq, DATEDIFF(qq,0,(@mydate + 124)), 0)     --下季度的第一天
                select        @nextYear = DATEADD(yy, DATEDIFF(yy,0,(@mydate + 366)), 0)         --下年的第一天
            select     o.fnumber as '客户编码',
                o.fname as '客户名称',
                sum(cs.br) as '本日内',
                sum(cs.bw) as '本周内',
                sum(cs.bm) as '本月内',
                sum(cs.bq) as '本季度内',
                sum(cs.byy) as '本年内'
            from(   
                select     t.FSupplyID,
                    sum(e.FConsignAmount) as 'br',0 as 'bw', 0 as 'bm',0 as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 = @mydate
                group by t.FSupplyID
                union all            
       
                select     t.FSupplyID,
                    0,sum(e.FConsignAmount) as 'bw', 0 as 'bm',0 as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisWeek and
                    e.FEntrySelfB0155 < @nextWeek
                group by t.FSupplyID
                union all
                select     t.FSupplyID,
                    0,0,sum(e.FConsignAmount) as 'bm', 0 as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisMonth and
                    e.FEntrySelfB0155 < @nextMonth
                group by t.FSupplyID
                union all
                select     t.FSupplyID,
                    0,0,0,sum(e.FConsignAmount) as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisQuarter and
                    e.FEntrySelfB0155 < @nextQuarter
                group by t.FSupplyID
                union all
                select     t.FSupplyID,
                    0,0,0,0,sum(e.FConsignAmount) as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisYear and
                    e.FEntrySelfB0155 < @nextYear
                group by t.FSupplyID
            ) as cs
                inner join
                t_Organization o on
                o.FItemID = cs.FSupplyID
                group by o.fnumber,o.fname
                having     sum(cs.bw)<> 0 or
                    sum(cs.bm)<> 0 or
                    sum(cs.bq)<> 0 or
                    sum(cs.byy)<> 0
    union all
            select     '9999',
                '合计',
                sum(cs.br) as '本日内',
                sum(cs.bw) as '本周内',
                sum(cs.bm) as '本月内',
                sum(cs.bq) as '本季度内',
                sum(cs.byy) as '本年内'
            from(   
                select     t.FSupplyID,
                    sum(e.FConsignAmount) as 'br',0 as 'bw', 0 as 'bm',0 as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 = @mydate
                group by t.FSupplyID
                union all            
       
                select     t.FSupplyID,
                    0,sum(e.FConsignAmount) as 'bw', 0 as 'bm',0 as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisWeek and
                    e.FEntrySelfB0155 < @nextWeek
                group by t.FSupplyID
                union all
                select     t.FSupplyID,
                    0,0,sum(e.FConsignAmount) as 'bm', 0 as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisMonth and
                    e.FEntrySelfB0155 < @nextMonth
                group by t.FSupplyID
                union all
                select     t.FSupplyID,
                    0,0,0,sum(e.FConsignAmount) as 'bq', 0 as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisQuarter and
                    e.FEntrySelfB0155 < @nextQuarter
                group by t.FSupplyID
                union all
                select     t.FSupplyID,
                    0,0,0,0,sum(e.FConsignAmount) as 'byy'
                from    ICStockBill t inner join
                    ICStockBillEntry e on
                    e.FInterID = t.FInterID
                where    e.FEntrySelfB0155 >= @thisYear and
                    e.FEntrySelfB0155 < @nextYear
                group by t.FSupplyID
            ) as cs
                inner join
                t_Organization o on
                o.FItemID = cs.FSupplyID
                having     sum(cs.bw)<> 0 or
                    sum(cs.bm)<> 0 or
                    sum(cs.bq)<> 0 or
                    sum(cs.byy)<> 0
                order by fnumber

    GO

    [ 本帖最后由 tyczp 于 2008-5-19 16:41 编辑 ]
    楼主热帖
    启用邀请码注册,提高发帖质量,建设交流社区

    该用户从未签到

    发表于 2008-5-23 10:04:31 | 显示全部楼层
    楼主,完全不知道你在卖什么呢.这样的东东...
    启用邀请码注册,提高发帖质量,建设交流社区
  • TA的每日心情
    开心
    2022-5-10 09:38
  • 签到天数: 338 天

    [LV.8]以坛为家I

    发表于 2008-5-23 13:45:58 | 显示全部楼层
    这样也来卖钱,都不知道是在卖什么的,是金蝶的,还是EXCELL的,起码也该有个效果图啊
    启用邀请码注册,提高发帖质量,建设交流社区
  • TA的每日心情
    奋斗
    前天 08:56
  • 签到天数: 1149 天

    [LV.10]以坛为家III

     楼主| 发表于 2008-7-7 17:25:40 | 显示全部楼层
    什么7锭。这个收费?没有吧!
    启用邀请码注册,提高发帖质量,建设交流社区
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表