Office中国论坛/Access中国论坛

标题: ACCESS中的长语句换行 [打印本页]

作者: ty_1029    时间: 2009-5-4 14:50
标题: ACCESS中的长语句换行
大体意思是在窗体中使用子窗体查询.但由于数据量比较大,考虑到直接将源数据记录属于子窗体,窗体加载时速度太慢,现在想通过在执行查询时,再将子窗体的数据源数据属于子窗体.

假如是这样的,在这段代码中插入语句
Me.DBquery.Form.RecordSource ="需插入的SQL语句"
由于过长,需要分行,试了几次用_ 或&_都不行,
望高手指教,需要插入的代码如下:"
SELECT DBBackup.tnoid, DBBackup.tnam, DBBackup.gnam, DBBackup.jial, Sum(DBBackup.xqnum) AS 需求量, Sum(DBBackup.dgnum) AS 订购量, Round(Sum(DBBackup.dgnum)*100/Sum(DBBackup.xqnum),0) & '%' AS 订单满足率, DBBackup.mark1, DBBackup.mark2, DBBackup.formats, DBBackup.scale, DBBackup.ctype, DBBackup.dtype FROM DBBackup GROUP BY DBBackup.tnoid, DBBackup.tnam, DBBackup.gnam, DBBackup.jial, DBBackup.mark1, DBBackup.mark2, DBBackup.formats, DBBackup.scale, DBBackup.ctype, DBBackup.dtype HAVING (((DBBackup.tnoid) Like IIf(IsNull(Forms!自助查询!Text1),'*','*' & Forms!自助查询!Text1 & '*')) And ((DBBackup.tnam) Like IIf(IsNull(Forms!自助查询!Text2),'*','*' & Forms!自助查询!Text2 & '*')) And ((DBBackup.gnam) Like IIf(IsNull(Forms!自助查询!Text3),'*',Forms!自助查询!Text3)) And ((DBBackup.jial) Like IIf(IsNull(Forms!自助查询!Text4),'*',Forms!自助查询!Text4)) And ((Sum(DBBackup.dgnum)) Between IIf(IsNull(Forms!自助查询!Text5),0,Forms!自助查询!Text5*Sum(DBBackup.xqnum)/100) And IIf(IsNull(Forms!自助查询!Text6),5000,Forms!自助查询!Text6*Sum(DBBackup.xqnum)/100)) And ((DBBackup.mark1) Like IIf(IsNull(Forms!自助查询!Text7),'*',Forms!自助查询!Text7)) And ((DBBackup.mark2) Like IIf(IsNull(Forms!自助查询!Text8),'*',Forms!自助查询!Text8)) And ((DBBackup.formats) Like IIf(IsNull(Forms!自助查询!Text9),'*',Forms!自助查询!Text9)) And ((DBBackup.scale) Like IIf(IsNull(Forms!自助查询!Text10),'*',Forms!自助查询!Text10)) And ((DBBackup.ctype) Like IIf(IsNull(Forms!自助查询!Text11),'*',Forms!自助查询!Text11)) And ((DBBackup.dtype) Like IIf(IsNull(Forms!自助查询!Text12),'*',Forms!自助查询!Text12)));
作者: chuang0321    时间: 2009-5-4 14:59
太长了,晕!可以考虑用几个变量来代替条件嘛
作者: asklove    时间: 2009-5-4 15:09
str="SELECT DBBackup.tnoid, DBBackup.tnam, DBBackup.gnam, DBBackup.jial, " & _
       " Sum(DBBackup.xqnum) AS 需求量, Sum(DBBackup.dgnum) AS 订购量," & _
   " Round(Sum(DBBackup.dgnum)*100/Sum(DBBackup.xqnum),0) " & _
         ...................
你是这样写的吗?第一句 DBBackup.jial, "空格"& "空格"_ (不加空格会出错)
        第二句  "空格SUm.....  (这里最前面不加空格也会出错)
                下面的一样格式
多试试就知道了,反正错误的格式字会变红。
作者: ty_1029    时间: 2009-5-4 15:28
呵呵,谢谢楼上的,原来问题就出在空格上,真费事啊~~

谢谢了~~~
作者: 红尘如烟    时间: 2009-5-4 15:42
发个文件上来,你这代码太长了,直接改不好改,少个空格什么的都很难看得出来
作者: todaynew    时间: 2009-5-4 20:28
就一个DBBackup表,完全可以删除字段前的DBBackup。
作者: winter_ice    时间: 2009-5-4 21:51
真的是很长啊
作者: ty_1029    时间: 2009-5-5 08:46
就一个DBBackup表,完全可以删除字段前的DBBackup。
todaynew 发表于 2009-5-4 20:28


晕,老是通过设计来完成,直接复制里面的SQL语句,也忘了精简~~

惭愧啊,谢谢各位老大了~~~~~~~~~




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3