2013-01-22 50 views
2

我是新來的網站,我有一些代碼,我在Access窗體中,我在SQL Server 2008中重做,它有SUM,IIF,和IsNumeric都在一行中,我很困惑如何在SQL中重寫這個。如何重新寫入SQL Server的MS Access表達式

Sum([Employee COUNT]*IIf(IsNull([2011]),0,CDbl([2011]))*IIf(IsNumeric([Length]),CDbl([Length]),0)) AS Cost 
+0

必須有不止於此,因爲這是訪問SQL。你是什​​麼意思的SQL? – Fionnuala

+0

哦,我很抱歉,我的意思是SQL Server – Andrew

+1

您可能想更正您的問題和標籤。 – Fionnuala

回答

6

我相信這會做你的需要:

Sum([Employee COUNT] 
    * (case 
      when [2011] Is Null 
      then 0 
      else cast([2011] as float) 
     end) 
    * (case 
      when IsNumeric([Length])= 1 
      then cast([Length] as float) 
      else 0 
     end)) AS Cost 
+0

完美,非常感謝您的幫助! – Andrew

0
SUM([Employee Count] 
    * COALESCE(
     [2011], 
     CASE WHEN 
     ISNUMERIC([2011]) = 1 
     THEN 
     CAST([2011] AS DECIMAL(18,4) 
     ELSE 
     0 
     END 
    ) 
    * CASE WHEN 
     ISNUMERIC([Length]) = 1 
    THEN 
     -- choose your own precision here. 
     CAST ([Length] AS DECIMAL(18,4)) 
    ELSE 
     0 
    END 
) AS Cost 
+0

已修改。謝謝。 –