可能重复:
嵌套 IIF 语句的 CASE 等效项
我正在尝试将以下 Access 查询转换为 T-SQL,但 IIF 语句出现问题。
访问查询
SELECT
qry_LAB_LOAD_Prequery2.Asset AS SITE_REF,
Format([Det],"00000") AS DET_,
IIf(IsNull([MT]),"0",IIf(Right([SP_Ref],2)="WZ"
And IsNull([LabLoadFileSuffix_MT])
And [MT]>0,CStr([MT]) & "CT",CStr([MT]) & [LabLoadFileSuffix_MT])) AS MT_COUNT,
IIf(IIf(IsNull([MT]),0,[MT])>=IIf(IsNull([IM]),0,[IM]),0,
IIf(IsNull([IM]),"0",IIf(Right([SP_Ref],2)="WZ"
And IsNull([LabLoadFileSuffix_IM]),CStr([IM])
& "CT",CStr([IM]) & [LabLoadFileSuffix_IM]))) AS IM_COUNT,
qry_LAB_LOAD_Prequery2.[2012 Sample Point] AS SP_REF, qry_LAB_LOAD_Prequery2.Area
FROM qry_LAB_LOAD_Prequery2
WHERE (((IIf(IsNull([IM]),0,[IM])+IIf(IsNull([MT]),0,[MT]))>0));
我试图转换它的一部分。谁能帮我纠正嵌套的 IID 语句,因为我不确定。
SQL 查询
SELECT qry_LAB_LOAD_Prequery2.Asset AS SITE_REF,
RIGHT('00000' + CAST([Det] AS VARCHAR(5)),5) AS DET_,
----- (the nested iff statements)
qry_LAB_LOAD_Prequery2.[2012 Sample Point] AS SP_REF,
qry_LAB_LOAD_Prequery2.Area
FROM qry_LAB_LOAD_Prequery2
where (ISNull([IM],0) + ISNULL([MT],0)) > 0