1

I’m using MS Query in Excel to execute the following 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. For a specific voucher (egvono = 51166554) I get the following rows:

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. It seems to accept the iif function at least, but the syntax is incorrect?

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?

4

1 回答 1

0

检查你的拼写egachid。列名是EGCHID-> 没有“A” 否则你可以试试:

SELECT CASE WHEN egachid CONTAINS 'GCAJA0' THEN False ELSE True END AS name
于 2016-08-12T12:51:48.477 回答