Sunday, March 11, 2012
Decode
My code looks like this: HELP!!
column EMPLOYEE format 9999999999 heading 'Employee'
COLUMN ANN FORMAT 99999999.99 heading 'Ann'
COLUMN FOUR format 99999999.99 heading 'FOUR'
COLUMN TOTALS format 99999999.99 heading 'Totals'
compute sum of FOUR on employee
compute sum of ANN on employee
compute sum of TOTALS on employee
SPOOL bc.TXT
SELECT employee,
SUM(DECODE(ded_code, 'ANN', ded_amt,0)) ANN,
SUM(DECODE(ded_code, '4', ded_amt,0)) FOUR,
SUM(DED_AMT)TOTALS
FROM PAYDEDUCTN
WHERE check_id IN (SELECT CHECK_ID
FROM PAYMASTR
WHERE CHECK_DATE = '22-Mar-02')
and ded_code in ('4', '5','403F', '403X', 'ANN')
GROUP by employee
/
SPOOL OUT
The output looks like this:
5639 .00 .00 267.05
:confused:The query seems to work fine without the WHERE clause for check_id.
SELECT employee,
SUM(DECODE(ded_code, 'ANN', ded_amt,0)) ANN,
SUM(DECODE(ded_code, '4', ded_amt,0)) FOUR,
SUM(DED_AMT) TOTALS
FROM PAYDEDUCTN
WHERE
ded_code in ('4', '5','403F', '403X', 'ANN')
A you sure you have records in table PAYDEDUCTN having check_id at 22-Mar-02 for the ded_code 'ANN' ?
Wednesday, March 7, 2012
Decimal Places Displayed
Hi,
I'm running the following query against a SQL Server 2003 database to receive the results below:
SELECT PayPeriod AS [Pay Period], SUM(PayHours) AS [Pay Hours]
FROM EmployeePayHours
GROUP BY PayPeriod
Pay Period Pay Hours
713 80714 120
717 59.5
718 80
719 80
A colleague of mine, however, is running the same query against the same database (using a different machine) and gets the following results.
Pay Period Pay Hours
713 80
714 120
717 59.500000000000021
718 79.999999999999972
719 79.999999999999972
Is there a setting somewhere that needs to be changed? Thanks.
This seems specious at best.
Are you certain that it is the exact same query running against the exact same database and the exact same table? (In the second example, it appears that the [Pay Hours] are either stored as floats, or that there is conversion to floats occurring some where in the process.)