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 > Time checks with dates

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-18-12, 04:26
ai_zaviour ai_zaviour is offline
Registered User
 
Join Date: Sep 2011
Posts: 53
Question Time checks with dates

Hello all..

Got a small problem to be solved

I have a Table which have ID and 2 date columns and One time field..

So what i want is when my application insert data with in entered date range the time should not be there..

Plz refer the attachment

For ID 001

FROM_DATE = 1/2/2012
TO_DATE = 1/16/2012
TIME = 15:10:00

So i want to make sure user can't enter same time [15:10:00] for ID 001 for above mention date range..

How can i do this..

this gives me no luck

SELECT ID
FROM HORSE_EVENTS
WHERE FROM_DATE BETWEEN :PARA1 AND :PARA2
AND TO_DATE BETWEEN :PARA1 AND :PARA2
AND TIME = :PARA3
Attached Thumbnails
Time checks with dates-1.jpg  
Reply With Quote
  #2 (permalink)  
Old 01-18-12, 07:04
tonkuma tonkuma is online now
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Please publish sample/test data in one of the format of
(1) DDL and INSERT statement.
or
(2) WITH common-table-expression.

Anyway, try an INSERT statement something like this(not tested)
Code:
INSERT INTO horse_events
SELECT new_id , new_from_date , new_to_date , new_time
 FROM  sysibm.sysdummy1
 WHERE NOT EXISTS(
       SELECT 0
        FROM  horse_events h
        WHERE h.id        = new_id
          AND h.from_date < new_to_date
          AND h.to_date   > new_from_date
          AND h.time      = new_time
       )
;

Last edited by tonkuma; 01-18-12 at 07:18.
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