条件格式 if then 语句

Conditional formatting if then statements

我正在尝试获取在 excel 中被视为 'nested if' 函数的内容以在查询中制定。查询的目标是创建一个视图,以便我可以比较两组数据。

如果在 excel 中,公式将如下所示:=IF(condition1=0,condition2,IF(condition2=0,condition3,condition1)).

我不断收到此错误消息:

我尝试使用的查询语言是:

drop view danburycomp 
go
create view danburycomp as
SELECT *, 
       TotalCash=CASE 
                   WHEN [cash out] = 0             THEN [cash counter cash in] 
                   WHEN [cash counter cash in] = 0 THEN [cash counter cash out] 
                                                   ELSE [cash out] 
                 END 
FROM   [trans jan-mar2016] 
WHERE  [account number] IN ( 'UNIQUEID1', 'UNIQUEID2' ) 
  AND ( [cash into trans] != 0 
         OR [cash out] != 0 ) 
  AND [date time trans] BETWEEN '2016-01-29' AND '2016-02-24' 

两件事:

  1. 而不是 TotalCash= 在 case 语句中的 end 之后放置 as TotalCash

  2. 案例逻辑关闭。如果 Cash out <> 0 并且 [Cash Counter Cash In]=0 它将 return [Cash Counter Cash Out] 我认为这不是想要的。

所以使用这个:

 drop view danburycomp 
go
create view danburycomp as
select *,
case 
    when[Cash Out]=0 and [Cash Counter Cash In]<>0 then [Cash Counter Cash In] 
    when [Cash Out]=0 and[Cash Counter Cash In]=0 then [Cash Counter Cash Out] 
    else [Cash Out]
end as TotalCash
from [Trans Jan-Mar2016]
where [Account Number] in ('UNIQUEID1', 'UNIQUEID2')
and ([Cash Into Trans] !=0 or [Cash Out]!=0)
and [Date Time Trans] between '2016-01-29' and '2016-02-24'