| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 924 人关注过本帖
标题:SQL 语句 新人求助!
只看楼主 加入收藏
hbutwzc
Rank: 1
等 级:新手上路
威 望:2
帖 子:376
专家分:0
注 册:2008-6-17
结帖率:100%
收藏
 问题点数:0 回复次数:1 
SQL 语句 新人求助!
一个表中数据按日,月统计。
两条语句合并。表为zjlrestmp
VarDate 为DTPicker1.value
 sqla为按日统计 sqlB为按月统计
AddCboBFname 一个函数 (如果COMBO控件不是空的,就增加相应的字段,
老调试不出来!
 sqlA = "select * from zjlrestmp where Left(CZDAT,8)='" & Format(VarDate, "yyyymmdd") & "' and bfname= '" & strBFname & "'and BWTAR=0 and pzflag=0 "
   
    sqlB = "select * from zjlrestmp where Left(CZDAT,6)='" & Format(VarDate, "yyyymm") & "' and Left(CZDAT,8)<='" & Format(VarDate, "yyyymmdd") & "'  and bfname= '" & strBFname & "'BWTAR=0 and pzflag=0 "
   
    If strMaktxx <> "" Then
        sqlA = "select * from (" & sqlA & ") as g where " & AddCboBFname(strMaktxx, "MAKTXX")
        
        sqlB = "select * from (" & sqlB & ") as h where " & AddCboBFname(strMaktxx, "MAKTXX")
      
    End If
   
    sqlA = "select * from (" & sqlA & ")"
   
    sqlB = "select * from (" & sqlB & ")"
  
    m = InStr(Trim(sqlA), "from")
    sqlA = Right(Trim(sqlA), Len(Trim(sqlA)) - m + 1)
   
    n = InStr(Trim(sqlB), "from")
    sqlB = Right(Trim(sqlB), Len(Trim(sqlB)) - n + 1)
   
  sqlA = "SELECT a.MAKTXX as maktxx, Count(a.CHEHAO) AS ch, Sum(a.MZQTY)-Sum(a.PZQTY) as sz, Sum(a.jZQTY) AS jz " & sqlA & " as a"
  
  sqlB = "SELECT b.MAKTXX as maktxx, Count(b.CHEHAO) AS ch, Sum(b.MZQTY)-Sum(b.PZQTY) as sz, Sum(b.jZQTY) AS jz  " & sqlB & "as b "
  
  sql = "select c.maktxx as maktxx,c.ch as ach,c.sz as asz,c.jz as ajz,d.maktxx as bmaktxx,d.ch as bch,d.sz as bsz,d.jz as bjz FROM (" & sqlA & ") as c right join (" & sqlB & ") as d on c.maktxx=d.maktxx"
  
  
  sql = "select "", e.maktxx,e.ach ,e.asz,e.ajz,e.bch ,e.bsz ,e.bjz from (" & sql & ") as e group by e.maktxx with rollup"
搜索更多相关主题的帖子: SQL 语句 新人 Left CZDAT 
2008-07-25 13:55
hbutwzc
Rank: 1
等 级:新手上路
威 望:2
帖 子:376
专家分:0
注 册:2008-6-17
收藏
得分:0 
没有人会啊?
2008-07-28 13:30
快速回复:SQL 语句 新人求助!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016483 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved