Crystal Reports 中的 whileprintingrecords 如何转换为 SQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14164052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:58:28  来源:igfitidea点击:

How does whileprintingrecords in Crystal Reports translate to SQL

sqlcrystal-reports

提问by Justin

I'm looking for the value of Group1total in a Crystal Report. My background is more centered around SQL and I'm trying to determine the logic behind the following:

我在 Crystal Report 中寻找 Group1total 的值。我的背景更集中在 SQL 上,我试图确定以下背后的逻辑:

//{@Group1total}
whileprintingrecords;
numbervar group1cost

//{@Group1cost}
whileprintingrecords;
numbervar group1cost := group1cost + {@group2total}

//{@Group2total}
whileprintingrecords;
numbervar group2cost

//{@Group2cost}
whileprintingrecords;
numbervar group2cost := group2cost + {@group3total}

//{@Group3total}
whileprintingrecords;
numbervar group3cost

//{@Group3cost}
whileprintingrecords;
numbervar group3cost := group3cost + {@group4total}

//{@Group4total}
whileprintingrecords;
numbervar group4cost

//{@Group4cost}
whileprintingrecords;
numbervar group4cost := group4cost + {XVR_projectcostbudget.cost_budget}

I'm noticing that simply doing the SUM of XVR_projectcostbudget.cost_budget in SQL is not yielding the same result as the Crystal Report. Any ideas?

我注意到在 SQL 中简单地执行 XVR_projectcostbudget.cost_budget 的 SUM 不会产生与 Crystal Report 相同的结果。有任何想法吗?

Thanks!

谢谢!

回答by craig

WhilePrintingRecords does NOT get translated to SQL. It only affect a given formula's calculation--essentially assigning it to one of the report's 'passes'. See Crystal Reports 9+ - Evaluation times and the multi-pass reporting model.

WhilePrintingRecords 不会被翻译成 SQL。它只影响给定公式的计算——本质上是将它分配给报告的“通过”之一。请参阅Crystal Reports 9+ - 评估时间和多通道报告模型

In your situation, I would suggest:

在你的情况下,我建议:

  • Inserting a summary on a formula or database field in all four of your groups' footers; this will create the fields that you can use in a formula field (you can create them manually, but this is easier)
  • Create a formula field that tallies the group summaries as desired
  • 在所有四个组的页脚中插入公式或数据库字段的摘要;这将创建您可以在公式字段中使用的字段(您可以手动创建它们,但这更容易)
  • 创建一个公式字段,根据需要记录组摘要

回答by Gary Thomann

Like Justin I can feel his frustration with Crystal Reports and putting this here to help others too.

像贾斯汀一样,我可以感受到他对 Crystal Reports 的挫败感,并把它放在这里也能帮助其他人。

Was trying to produce totals at various group levels and at the end of the report with the usual sum(decode( sql structure. In crystal was trying to simulate this using running total field with evaluate formula. The evaluation column being a code (all values are numeric but table column declared as string type :). Evaluation formula only provides "sum" functionality if the field type is numeric. So created a formula field to produce this column as a numeric. Great, sum function now usable in the running total with IFF ( , 1, 0). But would not produce a result! (ie blank)

试图在不同的组级别和报告末尾使用通常的 sum(decode( sql 结构。在水晶中试图使用运行总计字段和评估公式来模拟这一点。评估列是一个代码(所有值)是数字,但表列声明为字符串类型:) 如果字段类型为数字,则评估公式仅提供“求和”功能。因此创建了一个公式字段以将此列生成为数字。太好了,求和函数现在可用于运行总计与 IFF ( , 1, 0). 但不会产生结果!(即空白)

Switched to the Whileprintingrecords structure and working. How this works is succinctly put in the following article. http://crystalreportsblog.com/crystal-reports-running-totals/#comments

切换到 Whileprintingrecords 结构并工作。下面的文章将简要介绍其工作原理。 http://crystalreportsblog.com/crystal-reports-running-totals/#comments

Obviously putting this calc into the main sql query would be straight forward but old report with gui table links setup.

显然,将此 calc 放入主 sql 查询将很简单,但带有 gui 表链接设置的旧报告。