| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3814 人关注过本帖
标题:求一句SQL语句解决问题
取消只看楼主 加入收藏
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
sqlml="SELECT a1.编码,a1.名称,"
sqlml=+sqlml+"IIF(ISNULL(b1.本月发出),0,b1.本月发出) as 本月发出 from 客户编码 a1 left join"
sqlml=+sqlml+"(select khbm,sum(金额) as 本月发出 from 发出商品 日期 BETWEEN #&ncrq.# and #&jsrq.# group by khbm)b1 on a1.编码=b1.khbm"
sqlml=+sqlml+"order by a1.编码"

这样读取ACCESS表没问题,但是下面这样就不行了,提示语句错误,不知道为啥?

ncrq="2016-1-1"
jsrq="2016-11-30"
ycrq="2016-11-1"

 sqlml="SELECT a1.编码,a1.名称,"
sqlml=+sqlml+"IIF(ISNULL(b1.本月发出),0,b1.本月发出) as 本月发出,"
sqlml=+sqlml+"IIF(ISNULL(c1.本月开票),0,c1.本月开票) as 本月开票,"
sqlml=+sqlml+"IIF(ISNULL(d1.本月回款),0,d1.本月回款) as 本月回款,"
sqlml=+sqlml+"IIF(ISNULL(b2.累计发出),0,b2.累计发出) as 累计发出,"
sqlml=+sqlml+"IIF(ISNULL(c2.累计开票),0,c2.累计开票) as 累计开票,"
sqlml=+sqlml+"IIF(ISNULL(d2.累计回款),0,d2.累计回款) as 累计回款 from 客户编码 a1 "
 sqlml=+sqlml+"left join (select khbm,sum(金额) as 本月发出 from 发出商品 where 日期 BETWEEN #&ycrq.# and #&jsrq.# group by khbm)b1 on a1.编码=b1.khbm "
 sqlml=+sqlml+"left join (select khbm,sum(金额) as 本月开票 from 开票信息 where 开票日期 BETWEEN #&ycrq.# and #&jsrq.# group by khbm)c1 on a1.编码=c1.khbm "
 sqlml=+sqlml+"left join (select khbm,sum(回款金额) as 本月回款 from 回款信息 where 日期 BETWEEN #&ycrq.# and #&jsrq.#  group by khbm)d1 on a1.编码=d1.khbm "
 sqlml=+sqlml+"left join (select khbm,sum(金额) as 累计发出 from 发出商品 where 日期 BETWEEN #&ncrq.# and #&jsrq.#  group by khbm)b2 on a1.编码=b2.khbm "
 sqlml=+sqlml+"left join (select khbm,sum(金额) as 累计开票 from 开票信息 where 开票日期 BETWEEN #&ncrq.# and #&jsrq.#  group by khbm)c2 on a1.编码=c2.khbm "
 sqlml=+sqlml+"left join (select khbm,sum(回款金额) as 累计回款 from 回款信息 where 日期 BETWEEN #&ncrq.# and #&jsrq.#  group by khbm)d2 on a1.编码=d2.khbm "
 sqlml=+sqlml+"order by a1.编码"

IF SQLEXEC(mycon1,sqlml,'lsk')<0
    errmsg()
    RETURN
 ENDIF
 BROWSE
 USE IN lsk
2016-12-09 20:13
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
显示如下错误
图片附件: 游客没有浏览图片的权限,请 登录注册
2016-12-09 20:17
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
ncrq="2016-1-1"
jsrq="2016-11-30"
ycrq="2016-11-1"

TEXT TO sqlml NOSHOW TEXT PRETEXT 7
sqlml="SELECT a1.编码,a1.名称,"
sqlml=+sqlml+"IIF(ISNULL(b1.本月发出),0,b1.本月发出) as 本月发出,"
sqlml=+sqlml+"IIF(ISNULL(c1.本月开票),0,c1.本月开票) as 本月开票,"
sqlml=+sqlml+"IIF(ISNULL(d1.本月回款),0,d1.本月回款) as 本月回款,"
sqlml=+sqlml+"IIF(ISNULL(b2.累计发出),0,b2.累计发出) as 累计发出,"
sqlml=+sqlml+"IIF(ISNULL(c2.累计开票),0,c2.累计开票) as 累计开票,"
sqlml=+sqlml+"IIF(ISNULL(d2.累计回款),0,d2.累计回款) as 累计回款 from 客户编码 a1 left join "
sqlml=+sqlml+"(select khbm,sum(金额)     as 本月发出 from 发出商品 where 日期     BETWEEN #&ycrq.# and #&jsrq.# group by khbm)b1 on a1.编码=b1.khbm left join "
sqlml=+sqlml+"(select khbm,sum(金额)     as 本月开票 from 开票信息 where 开票日期 BETWEEN #&ycrq.# and #&jsrq.# group by khbm)c1 on a1.编码=c1.khbm left join "
sqlml=+sqlml+"(select khbm,sum(回款金额) as 本月回款 from 回款信息 where 日期     BETWEEN #&ycrq.# and #&jsrq.# group by khbm)d1 on a1.编码=d1.khbm left join "
sqlml=+sqlml+"(select khbm,sum(金额)     as 累计发出 from 发出商品 where 日期     BETWEEN #&ncrq.# and #&jsrq.# group by khbm)b2 on a1.编码=b2.khbm left join "
sqlml=+sqlml+"(select khbm,sum(金额)     as 累计开票 from 开票信息 where 开票日期 BETWEEN #&ncrq.# and #&jsrq.# group by khbm)c2 on a1.编码=c2.khbm left join "
sqlml=+sqlml+"(select khbm,sum(回款金额) as 累计回款 from 回款信息 where 日期     BETWEEN #&ncrq.# and #&jsrq.# group by khbm)d2 on a1.编码=d2.khbm "
sqlml=+sqlml+"order by a1.编码"
ENDTEXT

IF SQLEXEC(mycon1,sqlml,'lsk')<0
   errmsg()
   RETURN
ENDIF
BROWSE
USE IN lsk
图片附件: 游客没有浏览图片的权限,请 登录注册
2016-12-09 20:40
yll148
Rank: 2
等 级:论坛游民
威 望:3
帖 子:268
专家分:15
注 册:2012-7-3
收藏
得分:0 
谢谢各位朋友的指教,我弄明白了,谢谢谢谢!
2016-12-11 14:21
快速回复:求一句SQL语句解决问题
数据加载中...
 
   



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

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