-1

我正在尝试在 excel 中获取将被视为“嵌套 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' 
4

1 回答 1

0

两件事情:

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

  2. 案例逻辑已关闭。如果 Cash out <> 0 并且 [Cash Counter Cash In]=0 它将返回 [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'
于 2016-05-26T18:18:03.520 回答