Converting Access Code to SQL

前端 未结 2 1137
鱼传尺愫
鱼传尺愫 2021-01-29 13:49

I have the following code in Access and I need it to work in sql, the Is numeric portion is throwing me off.

Sum([Employee Count]*IIf(IsNumeric([Length]),[Length         


        
2条回答
  •  日久生厌
    2021-01-29 14:30

    You can also just filter "not isnumeric" out since 0 will not impact SUM aggregation.

    select
    Sum([Employee Count]*[Length]) AS Total_hours
    ...
    where isnumeric([Length]) = 1
    

    See code below.

    declare @table table (abc varchar(100))
    insert into @table
    select '1'
    union select '200'
    union select '200A'
    
    select sum(convert(int,abc))
    from @table
    where isnumeric(abc) = 1
    

    sqlfiddle

提交回复
热议问题