[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/06/2009 at 07:33AM PST, ID: 24878147 | Points: 500
[x]
Attachment Details

How do I select results when there are a mix of rows to compare to and no rows to compare to?

Asked by hmstechsupport in SQL Query Syntax, PL / SQL

I want to select data that is not meeting a certain criteria, in my case I want to select from rows where the the VALUE of a column called PSD_MIN (minutes worked on a certain day) is less than a certain value such as 480.  The SQL at the bottom works great for data that is in the table but not where there is not row in the detail table.  
in my example, for the week I would usually have 5 rows in PSDETAIL 1 for each day of the week with '20090831', '20090901', '20090902', '20090903' and '20090904'.  There is no rows in the table for '20090829' and '20090830' since these are Saturday and Sunday.and since folks do not work these days we do not store any data for them.
So the question is, how do I get a result back that includes the criteria set and also for  the missing rows as my example shows for Saturday and Sunday which in my example I specify I want to compare for these dates, but there are no rows to compare against.
Please keep in mind that I must write this SQL to be compatible with SQL Server, Oracle and Sybase.  I can separate the code of course for each db if required, but would prefer one that works for all db's or a solution for each.


SELECT DISTINCT PSH_KEY, PSH_WEDATE, 'Hours Missing' AS TSH_STATUS,EMH_NAME
FROM PSHEADER,EMPHIS,PSDETAIL,PSLINES
WHERE PSH_EMH=EMH_KEY AND PSL_PSH=PSH_KEY AND PSD_PSL=PSL_KEY
AND PSH_WEDATE = '20090904' AND ((PSD_DATE='20090829' AND PSD_MIN < 480) OR (PSD_DATE='20090830' AND PSD_MIN < 600) OR (PSD_DATE='20090831' AND PSD_MIN < 480)
OR (PSD_DATE='20090901' AND PSD_MIN < 480) OR (PSD_DATE='20090902' AND PSD_MIN < 480) OR
(PSD_DATE='20090903' AND PSD_MIN < 480) OR (PSD_DATE='20090904' AND PSD_MIN < 480))
ORDER BY PSH_WEDATE,EMH_NAME
[+][-]11/06/09 07:46 AM, ID: 25760070

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 07:48 AM, ID: 25760098

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 08:22 AM, ID: 25760485

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 08:52 AM, ID: 25760797

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/06/09 09:52 AM, ID: 25761310

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/09 10:07 AM, ID: 25761436

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625