通过万能报表做业务报表时,发现自动生成的SQL语句有问题。
具体操作如下;
1、新建数据源,拖销售订单的基本信息和收款计划到设计界面, 勾选显示基本信息的‘销售订单key’和收款计划上‘销售订单_收款计划KEY’
2、点击测试,弹出窗口中,收款计划KEY为空
3、复制脚本输出中的SQL语句:
SELECT TOP 1000
e0.FID,e0.FSaleOrgId, e1.FEntryID
FROM (
SELECT t0.FID AS FID,t0.FSALEORGID AS FSaleOrgId FROM T_SAL_ORDER t0 WHERE
t0.FOBJECTTYPEID = 'SAL_SaleOrder'
) e0
INNER JOIN (
SELECT t1.FEntryID AS FEntryID,t0.FID AS FID FROM T_SAL_ORDER t0 LEFT JOIN T_SAL_ORDERCLAUSE t1
ON (t0.FID = t1.FID ) WHERE
t0.FOBJECTTYPEID = 'SAL_SaleOrder'
) e1 ON e0.FID = e1.FID
检查语句,我需要取的数是收款计划的KEY,但是分析语句,取的却是订单条款的KEY。
4、测试1:将语句中表T_SAL_ORDERCLAUSE (t1)换成收款计划表T_SAL_ORDERPLANENTRY 后,取数正确。
5、测试2:在数据源设计界面,勾选“是否预收”,如图;
再检查输出语句,此时语句中为了取数‘是否预收’,又在语句中增加了收款计划表T_SAL_ORDERPLANENTRY ,并将其定义为t6
语句如下:
SELECT
e0.FID,e0.FSaleOrgId, e1.FEntryID,e1.FNeedRecAdvance
FROM (
SELECT t0.FID AS FID,t0.FSALEORGID AS FSaleOrgId FROM T_SAL_ORDER t0 WHERE
t0.FOBJECTTYPEID = 'SAL_SaleOrder'
) e0
INNER JOIN (
SELECT t1.FEntryID AS FEntryID,t0.FID AS FID,t6.FNEEDRECADVANCE AS FNeedRecAdvance FROM T_SAL_ORDER t0 LEFT JOIN T_SAL_ORDERCLAUSE t1
ON (t0.FID = t1.FID ) LEFT JOIN T_SAL_ORDERPLAN t6
ON (t0.FID = t6.FID ) WHERE
t0.FOBJECTTYPEID = 'SAL_SaleOrder'
) e1 ON e0.FID = e1.FID
此时,若将语句倒数第六行,select后面的t1(T_SAL_ORDERCLAUSE )改成t6(T_SAL_ORDERPLAN ),取数正确
结论,若在设计器中,每个表和每个单据体的别名是固定的(猜测),则问题的根源所在是:销售订单_收款计划key的取数语句错误,应该是t6.FEntryID,而不是t1.FEntryID。(经测试收款计划表的别名是t6,订单条款表的别名是t1)