If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Day of Week selection

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-08-09, 14:08
Xtrout Xtrout is offline
Registered User
 
Join Date: Jul 2009
Posts: 5
Day of Week selection

Hi Folks,

New to DB2 so I am trying to find out how to exclude weekends in a query. In sql it is...

Where (DATEPART(dw, Testdatetime) > 1) AND (DATEPART(dw, Testdatetime) < 7)

...but I cannot for the life of me figure out, or find online how to do this in DB2.

Can someone be as so kind as to provide me the syntax?

Thanks
Reply With Quote
  #2 (permalink)  
Old 07-08-09, 14:12
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
DAYOFWEEK(Testdatetime) - return range 1-7, where 1 represents Sunday.

DAYOFWEEK_ISO(Testdatetime) - range 1-7, where 1 represents Monday.
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #3 (permalink)  
Old 07-08-09, 14:17
Xtrout Xtrout is offline
Registered User
 
Join Date: Jul 2009
Posts: 5
So would that be...

DAYOFWEEK(Testdatetime) - return range 2-6

...if I want to exclude Sat and Sun?

Thanks
Reply With Quote
  #4 (permalink)  
Old 07-08-09, 14:21
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
yeh , right

Quote:
Originally Posted by Xtrout
So would that be...

DAYOFWEEK(Testdatetime) - return range 2-6

...if I want to exclude Sat and Sun?

Thanks
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #5 (permalink)  
Old 07-08-09, 14:23
Xtrout Xtrout is offline
Registered User
 
Join Date: Jul 2009
Posts: 5
The full query is...
SELECT start_date, tran_id, SUM(MIPS + IMS_MIPS) AS MIPS, SUM(tran_count) AS tran_count, SUM(resp_sec) AS resp_sec, SUM(CPU_sec) AS CICS_CPU_sec,
SUM(IMS_CPU_sec) AS IMS_CPU_sec, SUM(MIPS) AS CICS_MIPS, SUM(IMS_MIPS) AS IMS_MIPS
FROM (SELECT start_date, CASE WHEN tran_id IN ('FLOE', 'APOE', 'UW70', 'IR02', 'DRIV', 'DOCC', 'UWDR', 'MXPF', 'LDPF', 'POIN', 'LCLO', 'GFES', 'WFST',
'GATE', 'CONL', 'UP1K', 'RTEM', 'ULET', 'IL65', 'INSR', 'WRKS', 'TAX1', 'EMUL', 'LDPC', 'LPLI', 'L70I', 'CSNC', 'LEXM', 'EM1Q', 'LPBR',
'UPAT', 'EC01', 'DNTN', 'EDDD', 'FXDD', 'ALLB', 'IL60', 'GFGT', 'APBB', 'LMST') THEN tran_ID ELSE '*Other' END AS tran_id, tran_count,
resp_sec, CPU_sec, IMS_CPU_sec, MIPS, IMS_MIPS
FROM DZ001.dZtvcidA_mips
WHERE (start_date >= ?) AND (start_date < ?) AND (mvs_sys_id = '0600') AND (region_id IN ('PRDA', 'PRD2', 'PRD3', 'PRD4', 'PRD5', 'PRD6',
'PRD7', 'PRD8', 'PRD9'))) a
GROUP BY start_date, tran_id
ORDER BY 1, 2
Reply With Quote
  #6 (permalink)  
Old 07-08-09, 14:26
Xtrout Xtrout is offline
Registered User
 
Join Date: Jul 2009
Posts: 5
came back as invalid. is there a particular place within the query it needs to go? I put it in the 'Where' portion and it came back invalid.
Reply With Quote
  #7 (permalink)  
Old 07-08-09, 14:36
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
it has to go in the where clause .. Did you check in a simple query ???

what version and platform are you on ???

can you post the 'invalid' query and the message too
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #8 (permalink)  
Old 07-08-09, 14:41
Xtrout Xtrout is offline
Registered User
 
Join Date: Jul 2009
Posts: 5
Derr...I found my issue, I used the wrong datetime field name...I wrote it out like (DAYOFWEEK(start_date) > 1) AND (DAYOFWEEK(start_date) < 7) and it worked perfectly. Thanks so much for your help Sathyaram!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On