ernie_shah
asked on
DISTINCT ROW IN GRIDVIEW
I want to retrieve rows of data showing for each employee one value for Amount based on the criteria set.
So as in the example, only one record for emp_id 12894 or 15950 should be shown.
However, when I run the query I obtain individual entries for the specific criteria but not one row that sums the unit charged or amount field.
I am not using any vb code. My sql statement in the querybuilder is not generating unique records by employee id and as such my gridview does not display what I need.
See attached
Any help will be appreciated.
SCREENSHOT.doc
So as in the example, only one record for emp_id 12894 or 15950 should be shown.
However, when I run the query I obtain individual entries for the specific criteria but not one row that sums the unit charged or amount field.
I am not using any vb code. My sql statement in the querybuilder is not generating unique records by employee id and as such my gridview does not display what I need.
See attached
Any help will be appreciated.
SCREENSHOT.doc
ASKER
This does not work. No results are generated using the AND rather than the OR at line 31 and line 39.
First, there are lot of syntactical errors in your query.
Second, I have not changed anything except commenting unwanted columns in GROUP BY clause.
If that does not work, you have issues in your original query.
Second, I have not changed anything except commenting unwanted columns in GROUP BY clause.
If that does not work, you have issues in your original query.
ASKER
I don't understand. The query below works when I use OR at line 31 and 39.
The problem is that I am not achieving the desired result.
Instead of being able to view one record per employee that shows the sum of amount,
I am seeing individual transactions for the employee.
SELECT softech.GLTABLE_ARC.EMPL_I D,
softech.EMPLOYEE.FIRST_NAM E,
softech.EMPLOYEE.LAST_NAME ,
softech.GLTABLE_ARC.ACCOUN T_CODE,
SUM(softech.GLTABLE_ARC.AM OUNT) AS AMOUNT,
softech.GLTABLE_ARC.SEGMEN T1,
SUM(softech.GLTABLE_ARC.UN ITS_CHARGE D) AS UNITS_CHARGED,
SUBSTR(softech.GLTABLE_ARC .ACCOUNT_C ODE, 7, 2) AS LASTSEVENAC
FROM softech.EMPLOYEE,
softech.GLTABLE_ARC
WHERE softech.EMPLOYEE.EMPL_ID = softech.GLTABLE_ARC.EMPL_I D
GROUP BY --softech.GLTABLE_ARC.CYCL E_NO,
--softech.GLTABLE_ARC.PAY_ YEAR,
--softech.GLTABLE_ARC.OOC_ RUN,
softech.GLTABLE_ARC.EMPL_I D,
softech.EMPLOYEE.FIRST_NAM E,
softech.EMPLOYEE.LAST_NAME ,
--softech.GLTABLE_ARC.CODE _TYPE,
--softech.GLTABLE_ARC.CODE _FIELD,
softech.GLTABLE_ARC.ACCOUN T_CODE,
softech.GLTABLE_ARC.SEGMEN T1,
SUBSTR(softech.GLTABLE_ARC .ACCOUNT_C ODE, 7, 2)
HAVING ( softech.GLTABLE_ARC.CYCLE_ NO = 4 )
AND ( softech.GLTABLE_ARC.PAY_YE AR = 2013 )
AND ( softech.GLTABLE_ARC.OOC_RU N >= TO_DATE('4/16/2013', 'MM/DD/YYYY') )
AND ( softech.GLTABLE_ARC.CODE_F IELD = '771'
OR softech.GLTABLE_ARC.CODE_F IELD = '773'
OR softech.GLTABLE_ARC.CODE_F IELD = '779'
OR softech.GLTABLE_ARC.CODE_F IELD = '780' )
AND ( SUBSTR(softech.GLTABLE_ARC .ACCOUNT_C ODE, 7, 2) LIKE '70' )
OR (softech.GLTABLE_ARC.CYCLE _NO = 4)
AND ( softech.GLTABLE_ARC.PAY_YE AR = 2013 )
AND ( softech.GLTABLE_ARC.OOC_RU N IS NULL )
AND ( softech.GLTABLE_ARC.CODE_F IELD = '771'
OR softech.GLTABLE_ARC.CODE_F IELD = '773'
OR softech.GLTABLE_ARC.CODE_F IELD = '779'
OR softech.GLTABLE_ARC.CODE_F IELD = '780' )
AND ( SUBSTR(softech.GLTABLE_ARC .ACCOUNT_C ODE, 7, 2) LIKE '70' )
OR ( softech.GLTABLE_ARC.CYCLE_ NO = 5 )
AND ( softech.GLTABLE_ARC.PAY_YE AR = 2013 )
AND ( softech.GLTABLE_ARC.OOC_RU N <= TO_DATE('5/15/2013', 'MM/DD/YYYY') )
AND ( softech.GLTABLE_ARC.CODE_F IELD = '771'
OR softech.GLTABLE_ARC.CODE_F IELD = '773'
OR softech.GLTABLE_ARC.CODE_F IELD = '779'
OR softech.GLTABLE_ARC.CODE_F IELD = '780' )
AND ( SUBSTR(softech.GLTABLE_ARC .ACCOUNT_C ODE, 7, 2) LIKE '70' )
ORDER BY softech.GLTABLE_ARC.EMPL_I D
Thanks
The problem is that I am not achieving the desired result.
Instead of being able to view one record per employee that shows the sum of amount,
I am seeing individual transactions for the employee.
SELECT softech.GLTABLE_ARC.EMPL_I
softech.EMPLOYEE.FIRST_NAM
softech.EMPLOYEE.LAST_NAME
softech.GLTABLE_ARC.ACCOUN
SUM(softech.GLTABLE_ARC.AM
softech.GLTABLE_ARC.SEGMEN
SUM(softech.GLTABLE_ARC.UN
SUBSTR(softech.GLTABLE_ARC
FROM softech.EMPLOYEE,
softech.GLTABLE_ARC
WHERE softech.EMPLOYEE.EMPL_ID = softech.GLTABLE_ARC.EMPL_I
GROUP BY --softech.GLTABLE_ARC.CYCL
--softech.GLTABLE_ARC.PAY_
--softech.GLTABLE_ARC.OOC_
softech.GLTABLE_ARC.EMPL_I
softech.EMPLOYEE.FIRST_NAM
softech.EMPLOYEE.LAST_NAME
--softech.GLTABLE_ARC.CODE
--softech.GLTABLE_ARC.CODE
softech.GLTABLE_ARC.ACCOUN
softech.GLTABLE_ARC.SEGMEN
SUBSTR(softech.GLTABLE_ARC
HAVING ( softech.GLTABLE_ARC.CYCLE_
AND ( softech.GLTABLE_ARC.PAY_YE
AND ( softech.GLTABLE_ARC.OOC_RU
AND ( softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
AND ( SUBSTR(softech.GLTABLE_ARC
OR (softech.GLTABLE_ARC.CYCLE
AND ( softech.GLTABLE_ARC.PAY_YE
AND ( softech.GLTABLE_ARC.OOC_RU
AND ( softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
AND ( SUBSTR(softech.GLTABLE_ARC
OR ( softech.GLTABLE_ARC.CYCLE_
AND ( softech.GLTABLE_ARC.PAY_YE
AND ( softech.GLTABLE_ARC.OOC_RU
AND ( softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
OR softech.GLTABLE_ARC.CODE_F
AND ( SUBSTR(softech.GLTABLE_ARC
ORDER BY softech.GLTABLE_ARC.EMPL_I
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I will try this in my query builder and get back to you. Off work till Monday so you will hear from me then. Thanks so much for your time and assistance. Hear from me soon.
ASKER
Good Morning:
My issue has been resolved.
Thanks alot.
My issue has been resolved.
Thanks alot.
Open in new window