Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
访问SQL的iif语句太多_Sql_Ms Access - Fatal编程技术网

访问SQL的iif语句太多

访问SQL的iif语句太多,sql,ms-access,Sql,Ms Access,我有一个大的嵌套iif语句。我有16个不同的字段,我需要根据它们的初始值为它们赋值1或0。这是: select iif(overlimitexception = "Yes",0,1) as OverLimit, iif(CashOutageIdentified = "Yes",0,1) AS CashOutage, iif(MissingAuditIdentified = "Yes",0,1) AS MissingAudit, iif(NightDropObserved = "Y

我有一个大的嵌套iif语句。我有16个不同的字段,我需要根据它们的初始值为它们赋值1或0。这是:

select
  iif(overlimitexception = "Yes",0,1) as OverLimit,
  iif(CashOutageIdentified = "Yes",0,1) AS CashOutage,
  iif(MissingAuditIdentified = "Yes",0,1) AS MissingAudit,
  iif(NightDropObserved = "Yes",0,1) AS NightDrop, 
  iif(SecurityTestComplete = "No",0,1) AS SecurityTest,
  iif(CashPatternIdentified = "Yes",0,1) AS CashPattern,
  iif(AllClearChange = "No",0,1) AS AllClear,
  iif(RobberyKitReview = "No",0,1),
  iif(EvacPlanReview = "No",0,1),
  iif(KeyComboIssue = "Yes",0,1) AS KeyCombo,
  iif(DualControlIssue = "Yes",0,1) AS DualControl,
  iif(TaIssue = "Yes", 0,1) AS TA,
  iif(CleanDeskIssue = "Yes",0,1) AS CleanDesk,
  iif(MonthlyOpsIssue = "Yes",0,1) AS MonthlyOps,
  iif(OverShortIssue = "Yes",0,1) AS OverShort,
  iif(CashTargetIssue = "Yes",0,1) AS CashTarget 
From [ROM Acknowledgement]

如果我只处理一个领域,我可以很容易地解决这个问题,但我处理的是16个领域。有更好的方法吗?谢谢你的帮助

如果您对
iif
过敏,以下是一种可能的替代方法:

select
    1+(overlimitexception = "Yes") as OverLimit,
    1+(CashOutageIdentified = "Yes") AS CashOutage,
    1+(MissingAuditIdentified = "Yes") AS MissingAudit,
    1+(NightDropObserved = "Yes") AS NightDrop, 
    1+(SecurityTestComplete = "No") AS SecurityTest,
    1+(CashPatternIdentified = "Yes") AS CashPattern,
    1+(AllClearChange = "No") AS AllClear,
    1+(RobberyKitReview = "No"),
    1+(EvacPlanReview = "No"),
    1+(KeyComboIssue = "Yes") AS KeyCombo,
    1+(DualControlIssue = "Yes") AS DualControl,
    1+(TaIssue = "Yes") AS TA,
    1+(CleanDeskIssue = "Yes") AS CleanDesk,
    1+(MonthlyOpsIssue = "Yes") AS MonthlyOps,
    1+(OverShortIssue = "Yes") AS OverShort,
    1+(CashTargetIssue = "Yes") AS CashTarget 
from 
    [ROM Acknowledgement]
假设在所提到的字段中只有“否”和“是”值,您可以这样写

  1 - eval(overlimitexception) as OverLimit,
  -eval(SecurityTestComplete) AS SecurityTest,
还是快一点

  3 - len(overlimitexception) as OverLimit,
  -2 + len(SecurityTestComplete) AS SecurityTest,

不,我不这么认为。顺便说一句,那些
iif
s不是嵌套的。但你真的想将“是”标记为0吗?你是对的,它们不是。我知道,我们正在计算风险评估的总分,越低=越适合我们的目的。谢谢我想知道为什么您首先将是/否信息存储为文本字段?请更好地指定。每列只有一个操作,再简单不过了。