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
You will replace the IIF()
with a CASE
expression. The IsNumeric() is valid in SQL Server:
Sum([Employee Count]*
case when IsNumeric([Length]) = 1
then [Length]
else 0 end) AS Total_hours,
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