Crystal 显示最新的公式

Crystal Formula to display the latest

A table 具有从锻炼 1 到锻炼 7 的锻炼列。

我想创建公式来检查最新的锻炼(更高)并将其显示在 crystal 报告中。例如,检查 workout7 是否有值,然后在任何其他锻炼列之前显示它,否则检查 workout6,如果有值,则在其他列之前显示它等等。

但我认为 if-else 语句不是执行此工作的正确选择。正确的做法是什么?

如有任何帮助,我们将不胜感激,

你可以两面都做,最好在 sqlserver 端做以获得更好的性能。

对于 sqlserver 端,这是一个示例。

create table tempworkout (dmv_workpatten varchar(50), dmv_workin1 varchar(50) , dmv_workout1 varchar(50)
, dmv_workin2 varchar(50) , dmv_workout2 varchar(50)
, dmv_workin3 varchar(50) , dmv_workout3 varchar(50)
, dmv_workin4 varchar(50) , dmv_workout4 varchar(50)
, dmv_workin5 varchar(50) , dmv_workout5 varchar(50)
, dmv_workin6 varchar(50) , dmv_workout6 varchar(50)
, dmv_workin7 varchar(50) , dmv_workout7 varchar(50))

insert into tempworkout values ('WP1', 1,2,3,4,5,6,7,8,9,10,11,12,13,14)
,('WP1', 2,3,4,5,6,7,8,9,10,11,12,13,14, 15)
,('WP1', 3,4,5,6,7,8,9,10,11,12,13,null,15,null)
,('WP1', 4,5,6,7,8,9,10,11,12,null,14,null,16,null)
,('WP1', 4,5,6,7,8,9,10,null,12,null,14,null,16,null)

select * from tempworkout

select COALESCE(dmv_workout7, COALESCE(dmv_workout6, COALESCE(dmv_workout5,COALESCE(dmv_workout4,COALESCE(dmv_workout3,COALESCE(dmv_workout2,dmv_workout1)))))),
* from tempworkout

insert into tempworkout values ('WP1', 1,null,3,null,5,null,7,null,9,null,11,null,13,null)

select COALESCE(dmv_workout7, COALESCE(dmv_workout6, COALESCE(dmv_workout5,COALESCE(dmv_workout4,COALESCE(dmv_workout3,COALESCE(dmv_workout2,dmv_workout1)))))),
* from tempworkout
drop table tempworkout

您在 crystal 报告中的比较有问题。在 crystal 报告端,您可以使用:(检查语法)

if Not IsNull({table1.id})  then
   (if {table1.name} <> "a" then
      var1 := "Hello"
   else
      var1 := "Hi";)
else
   var1 := "Bye";

http://scn.sap.com/thread/3279432

Nested if else in Crystal Reports

如果不为null需要检查value,如果不为null则打印,否则继续按降序检查步骤,找到value就打印。

if NOT ISNULL ({EB_Tam_DailyMv.dmv_workout10}) then
{EB_Tam_DailyMv.dmv_workout10}

else  if NOT  ISNULL ({EB_Tam_DailyMv.dmv_workout9}) then
{EB_Tam_DailyMv.dmv_workout9}

else if  NOT ISNULL ({EB_Tam_DailyMv.dmv_workout8}) then 
{EB_Tam_DailyMv.dmv_workout8}

else if  NOT ISNULL ({EB_Tam_DailyMv.dmv_workout7}) then 
{EB_Tam_DailyMv.dmv_workout7} 

else if NOT ISNULL({EB_Tam_DailyMv.dmv_workout6}) then 
{EB_Tam_DailyMv.dmv_workout6}

else if NOT ISNULL({EB_Tam_DailyMv.dmv_workout5}) then 
{EB_Tam_DailyMv.dmv_workout5}

 else if NOT ISNULL({EB_Tam_DailyMv.dmv_workout4}) then 
 {EB_Tam_DailyMv.dmv_workout4}

 else if NOT ISNULL ({EB_Tam_DailyMv.dmv_workout3}) then 
 {EB_Tam_DailyMv.dmv_workout3}

else if NOT ISNULL ({EB_Tam_DailyMv.dmv_workout2}) then 
{EB_Tam_DailyMv.dmv_workout2}

else if NOT ISNULL ({EB_Tam_DailyMv.dmv_workout1}) then 
{EB_Tam_DailyMv.dmv_workout1}

else "00:00"