Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TSQL - Query Not Extracting Data

Status
Not open for further replies.

JcTon

MIS
Oct 26, 2007
16
US
Not quite able to figure out the problem/resolution to the following query not extracting data. Query is designed to extract all current employees for the month-employees that do not have a eligible begin dt prior to the first day of the month. (Note, employees can have multiple elibility spans where there are multiple eligible begin dates.)

Any advice greatly appreciated.

SELECT DISTINCT ME.EMPLOYEE_ID
, M.EMP_ACCOUNT_NBR
, M.EMP_FIRST_NM
, M.EMP_LAST_NM
, M.EMP_BIRTH_DT
, ME.EMP_PRODUCT_CD
, ME.EMP_ELIGIBLE_BEGIN_DT
, MA.EMP_CITY_NM
, MA.EMP_STATE_CD
, MA.EMP_ZIP

FROM MEMBER M (NOLOCK)
INNER JOIN MERCHANT_ELIGIBILITY ME (NOLOCK)
ON M.EMPLOYEE_ID = ME.EMPLOYEE_ID

INNER JOIN MERCHANT_ADDRESS MA (NOLOCK)
ON M.EMPLOYEE_ID = MA.EMPLOYEE_ID

WHERE

ME.EMP_ELIGIBLE_BEGIN_DT >= '11/01/2007'
AND NOT EXISTS
(SELECT * from MERCHANT_ELIGIBILITY ME1
WHERE ME.EMPLOYEE_ID = ME1.EMPLOYEE_ID
AND EMP_ELIGIBLE_BEGIN_DT < '11/01/2007')

AND ME.EMP_ELIGIBLE_END_DT >= '11/01/2007'
AND MA.EMP_ADDR_BEGIN_DT >= '05/1/2006'

AND ME.EMP_ELIGIBLE_BEGIN_DT BETWEEN MA.EMP_ADDR_BEGIN_DT AND MA.EMP_ADDR_END_DT

GROUP BY ME.EMPLOYEE_ID
, M.EMP_ACCOUNT_NBR
, M.EMP_FIRST_NM
, M.EMP_LAST_NM
, M.EMP_BIRTH_DT
, ME.EMP_PRODUCT_CD
, ME.EMP_ELIGIBLE_BEGIN_DT
, MA.EMP_CITY_NM
, MA.EMP_STATE_CD
, MA.EMP_ZIP

 
Have you narrowed down what part of the query is stopping you from getting results? Try commenting out some of the where conditions or joins.

Regardless of the result, remove either the GROUP BY or the DISTINCT - there's no need to SELECT DISTINCT when you're already grouping by the same values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top