简体   繁体   English

MS Query Excel iif表达式语法错误

[英]MS Query Excel iif expression syntax error

I'm using MS Query in Excel to execute the following query: 我在Excel中使用MS Query来执行以下查询:

select 
iif(egachid <>'GCAJA0', True, False)
from fgledg
where egcono='1'and egdivi='D30'and egvono=51166554

I have a tabel, fgledg, that contains a column, egchid. 我有一个tabel,fgledg,包含一个列,egchid。 For a specific voucher (egvono = 51166554) I get the following rows: 对于特定的凭证(egvono = 51166554),我得到以下行:

EGCONO    EGDIVI    EGYEA4  EGVONO      EGCHID
1         D30       2015    51166554    GCAJA0
1         D30       2015    51166554    GCAJA0
1         D30       2015    51166554    GCAJA0
1         D30       2015    51166554    GCAJA0
1         D30       2015    51166554    SEBSHHASP
1         D30       2015    51166554    SEBSHHASP
1         D30       2015    51166554    SEBSHHASP

I would like my query to return True if the column egchid contains other values than GCAJA0 and false if the column only contains the value GCAJA0, but I keep getting error messages no matter how i write the syntax. 如果列egchid包含除GCAJA0之外的其他值,我希望我的查询返回True;如果列只包含值GCAJA0,我希望返回false,但无论我如何编写语法,我都会收到错误消息。 It seems to accept the iif function at least, but the syntax is incorrect? 它似乎至少接受了iif函数,但语法不正确?

I have tried diffrent variations of writing the syntax, but get the following error messages: 我尝试过编写语法的不同变体,但得到以下错误消息:

IIf(egachid <>'GCAJA0', True, False)        Token <> was not valid
IIf(egachid = 'GCAJA0', False, True)        Token = was not valid
IIf([egachid] <>'GCAJA0', True, False)      Token [ was not valid
IIf([egachid] <>'GCAJA0', 'True', 'False')  Token [ was not valid

What am I doing wrong? 我究竟做错了什么?

Check your spelling of egachid . 检查你的egachid的拼写。 The column name is EGCHID -> no "A" Else you can try: 列名是EGCHID - >否“A”你可以尝试:

SELECT CASE WHEN egachid CONTAINS 'GCAJA0' THEN False ELSE True END AS name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM