2

我是该站点的新手,我对我在 SQL Server 2008 中重做的 Access 表单中的一些代码有疑问,它在一行中包含 SUM、IIF 和 IsNumeric,我对如何重写它感到困惑在 SQL 中。

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

2 回答 2

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
于 2013-01-22T17:32:31.630 回答
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
于 2013-01-22T17:33:19.663 回答