I would like to perform a simple math on SQL select statement. can some body suggest how to do this? I would like to have a column (indirectlabor - indleave - indsick - indstat) as ind.
for example. The following code does not work.
SELECT lmltimecardid as timecard,
SUM( case lmlTimecardType when 1 then lmllaborhours else 0 end) directlabor,
SUM( case lmlTimecardType when 2 then lmllaborhours else 0 end) indirectlabor,
SUM( case lmlTimecardType when 3 then lmllaborhours else 0 end) idlelabor,
SUM(case lmlIndirectLaborID when 'LEAVE' then lmllaborhours else 0 end) IndLeave,
SUM(case lmlIndirectLaborID when 'SICK' then lmllaborhours else 0 end) IndSick,
SUM(case lmlIndirectLaborID when 'STAT' then lmllaborhours else 0 end) IndStat,
(indirectlabor - indleave - indsick - indstat) as ind
FROM TIMECARDLINES GROUP BY LMLTIMECARDID
for example. The following code does not work.
SELECT lmltimecardid as timecard,
SUM( case lmlTimecardType when 1 then lmllaborhours else 0 end) directlabor,
SUM( case lmlTimecardType when 2 then lmllaborhours else 0 end) indirectlabor,
SUM( case lmlTimecardType when 3 then lmllaborhours else 0 end) idlelabor,
SUM(case lmlIndirectLaborID when 'LEAVE' then lmllaborhours else 0 end) IndLeave,
SUM(case lmlIndirectLaborID when 'SICK' then lmllaborhours else 0 end) IndSick,
SUM(case lmlIndirectLaborID when 'STAT' then lmllaborhours else 0 end) IndStat,
(indirectlabor - indleave - indsick - indstat) as ind
FROM TIMECARDLINES GROUP BY LMLTIMECARDID