IIF([Add DVP Month].DevelopmentMonth>[Add DVP Month].COVMONTHS,
1,
IIF([STATUS]<>'1',
1,
IIF([Add DVP Month].PLANTYPE = 'A' and [Add DVP Month].newUsedProgram = 'U' and [Add DVP Month].COVMONTHS = 60 and [Add DVP Month].COVMILES = 100000 and [Add DVP Month].postedDt >= #1/31/2010#,
IIF([Add DVP Month].postedDt >= #1/31/2012#,
[EPMthd.PCM2],
IIF([Add DVP Month].postedDt >= #1/31/2010#,
[EPMthd.PCM1],
[EPMthd.PCM0])
),
IIF([Add DVP Month].COVMONTHS = 999,[EPMthd.2],
IIF([Add DVP Month].postedDt >= #1/31/2012#, [EPMthd.2],
IIF([Add DVP Month].postedDt >= #1/31/2010#, [EPMthd.1],
IIF([Add DVP Month].postedDt >= #1/31/2008#,
IIF([EPMthd.0] is null,
[EPMthd.8],
[EPMthd.0]
),
IIF([Add DVP Month].postedDt < #1/31/2008#,
IIF([EPMthd.8] is null,
IIF([Add DVP Month].COVMONTHS = 0,0,
[Add DVP Month].DevelopmentMonth/[Add DVP Month].COVMONTHS
),
[EPMthd.8]
),
IIF([Add DVP Month].COVMONTHS = 0,
0,
[Add DVP Month].DevelopmentMonth/[Add DVP Month].COVMONTHS
)
)
))))))
) AS [EP%]
更新:SQL Server 2012現在有一個IIF聲明。 http://msdn.microsoft.com/en-us/library/hh213574.aspx – Somantra 2012-06-13 18:19:31
@Somantra:true - 但在2010年12月還沒有人知道,並且OP在詢問SQL Server 2005. – 2012-06-13 18:20:19