problem with case statement [message #626100] |
Mon, 20 October 2014 13:49 |
|
bobghw
Messages: 34 Registered: July 2012
|
Member |
|
|
Hi
query needs to extract data for the previous day except on Mondays when it needs to pull Friday, Saturday and Sunday data.
Using a case statement for criteria and it pulls the previous days data but not the weekend data?
SELECT Ip.Adm_Date + Ip.Adm_Time / 86400 AS Admdatetime
, Ip.Pt_Code
, Cpi.Surname
, Cpi.First_Given_Name
, Ip.W_Code
, ''as "Reviewed/No MR completed "
, '' AS "MR < 24"
, '' AS "MR 24-36"
, '' AS "MR 36-48"
, '' AS "MR 48-60"
, '' AS "MR 60-72"
, '' AS "MR>72"
, '' AS "MR Finalised"
, '' AS "MR on Dx"
, '' AS "Pharm/Tech"
, '' AS "Met MR Criteria"
, '' as "Comments"
FROM K_Ipreg Ip, K_Cpireg Cpi
WHERE Ip.Pt_Code = Cpi.Pt_Code
AND Ip.Disch_Date IS NULL
AND Ip.Adm_Date BETWEEN ( ( CASE
WHEN TO_CHAR ( SYSDATE, 'd' ) = 1
THEN SYSDATE - 4
ELSE SYSDATE - 2
END ) )
AND SYSDATE
AND W_Code NOT IN ('ICW', 'NWB', 'ANTE', 'BABY', 'CHILD', 'DELI', 'ED', 'MATY', 'SCBU')
|
|
|
|
|
|
|
Re: problem with case statement [message #626148 is a reply to message #626107] |
Tue, 21 October 2014 08:27 |
joy_division
Messages: 4963 Registered: February 2005 Location: East Coast USA
|
Senior Member |
|
|
bobghw wrote on Mon, 20 October 2014 22:26Hi Thanks for the reply TO_CHAR ( SYSDATE, 'd' ) returns 1 for Monday, 2 for Tuesday etc..
Actually, it returns a '1' or a '2,' not a 1 or a 2. TO_CHAR return a string, not a number.
|
|
|
Re: problem with case statement [message #626153 is a reply to message #626148] |
Tue, 21 October 2014 12:21 |
Bill B
Messages: 1971 Registered: December 2004
|
Senior Member |
|
|
also if adm_date is trunc'ed (time removed) then you can use the following
AND Ip.Adm_Date BETWEEN
decode(TO_CHAR ( SYSDATE, 'DY' ),'MON',TRUNC(SYSDATE - 4),TRUNC(SYSDATE - 2))
AND TRUNC(SYSDATE)
|
|
|
|
Re: problem with case statement [message #626159 is a reply to message #626157] |
Tue, 21 October 2014 14:20 |
|
Michel Cadot
Messages: 68647 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
But are you sure that all your clients forever will be in New Zealand?
No, then switch to something like Bill's query, you can then force the language you want to use in the query:
SQL> select to_char(sysdate,'Dy','NLS_DATE_LANGUAGE=ENGLISH') en,
2 to_char(sysdate,'Dy','NLS_DATE_LANGUAGE=FRENCH') fr,
3 to_char(sysdate,'Dy','NLS_DATE_LANGUAGE=GERMAN') ge
4 from dual
5 /
EN FR GE
--- ---- --
Tue Mar. Di
Then you are not dependent on the client settings.
|
|
|
|
|
|
|
Re: problem with case statement [message #626166 is a reply to message #626164] |
Tue, 21 October 2014 14:35 |
|
Michel Cadot
Messages: 68647 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Yes, but maybe some day some one will interested by your product and will want to use it in his country.
Or maybe your hospital will be associated with an (or several) other one(s) in an other country in the same computer department or to use the same products in order to decrease the expense for the computer department
There are so may reasons a product won't stay where it was developed, it is a pity (even a shame) it has not been thought to be independent of the country, language or date format.
[Updated on: Tue, 21 October 2014 14:36] Report message to a moderator
|
|
|
|
|