表格包含从exercise1到workout7的锻炼列。
我想创建一个公式来检查最新的锻炼(更高)并将其显示在水晶报告中。例如,检查workout7是否有值然后在任何其他锻炼列之前显示它,否则检查workout6,如果是值,则在其他列之前显示它,依此类推。
但我认为if-else声明不是执行这项工作的正确选择。这样做的正确方法是什么?
任何帮助将不胜感激,
答案 0 :(得分:1)
如果值不为null,则需要检查该值,然后如果该值不为null,则打印它,否则继续检查降序方法中的步骤,并且只要找到该值就打印它。
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"
答案 1 :(得分:0)
你可以做到这一点,在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
您在水晶报告中的比较出现问题。在水晶报告方面,您可以使用:(检查语法)
if Not IsNull({table1.id}) then
(if {table1.name} <> "a" then
var1 := "Hello"
else
var1 := "Hi";)
else
var1 := "Bye";