假如是这样的,在这段代码中插入语句
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
呵呵,谢谢楼上的,原来问题就出在空格上,真费事啊~~