Parsing/Selecting DateTime fields

Please support our MS SQL advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jun 2008
Posts: 28
Reputation: cheapterp is an unknown quantity at this point 
Solved Threads: 2
cheapterp's Avatar
cheapterp cheapterp is offline Offline
Light Poster

Parsing/Selecting DateTime fields

 
0
  #1
Apr 22nd, 2009
I have a table off which I need to parse out the data using certain criteria. The table contains 3 datetime columns called 'ReadingTakenOn', 'StartedOn', and 'StoppedOn'

Here's the criteria for selecting the records:
The Dates in the 'ReadingTakenOn' column should lie between the Start Date and Stop Dates (both inclusive)

Now, I have to further pick out records from the above selected ones based on the 'Time' values as:
If the 'ReadingTakenOn' Time lies between the 'StartedOn' and 'StoppedOn'. I am not sure if I have been terribly clear on that, so here's an example:

Let's say the ReadingTakenOn column begins on 10/15/2006 08:00 and goes all the way down to 11/15/2006 18:30.

Now assume the value for 'StartedOn' is 10/26/2006 11:00 and 'StoppedOn' is 11/15/2006 16:00.

Now I want to obtain records from 10/26/2006 11:00 to 11/15/2006 16:00 and ignore records that occur before and after these dates+times.

I am struggling to write the WHERE clause for the SQL query to achieve this

Just FYI, I am using MS-SQL 2005.

Thanks in advance!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 220
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 33
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training

Re: Parsing/Selecting DateTime fields

 
0
  #2
Apr 23rd, 2009
USE BETWEEN CLAUSE. LIKE: WHERE A BETWEEN C AND D .
Let me know if i cant understand your problem.
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 28
Reputation: cheapterp is an unknown quantity at this point 
Solved Threads: 2
cheapterp's Avatar
cheapterp cheapterp is offline Offline
Light Poster

Re: Parsing/Selecting DateTime fields

 
0
  #3
Apr 23rd, 2009
Woww... I missed an easy one there. Thanks Saion!
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 16
Reputation: SQL_n00b is an unknown quantity at this point 
Solved Threads: 1
SQL_n00b's Avatar
SQL_n00b SQL_n00b is offline Offline
Newbie Poster

Re: Parsing/Selecting DateTime fields

 
0
  #4
Apr 23rd, 2009
I have a query similar to the original poster's, so I thought I might post it here.

I want to do exactly what he/she is trying to- the only difference being that my data comes from 2 different tables. The date and time columns that correspond to the 'StartedOn' and 'StoppedOn' columns are in one table and the column corresponding to 'ReadingTakenOn' is in another table. The rest of the objective is exactly the same.

Any help is appreciated!

TIA!

P.S: I understand might have hijacked the thread here and if that is a serious flouting of the forum rules, I will be happy to start a new thread!
Last edited by Ezzaral; Apr 23rd, 2009 at 3:10 pm. Reason: Snipped "fake sig" links.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 220
Reputation: mail2saion is an unknown quantity at this point 
Solved Threads: 33
mail2saion's Avatar
mail2saion mail2saion is offline Offline
Posting Whiz in Training

Re: Parsing/Selecting DateTime fields

 
0
  #5
Apr 26th, 2009
Let start is in table A and stopeed is in table b then first apply join then apply between clause. LIKE SELECT A.*,B.* FROM A INNER JOIN B ON A.ID=B.ID WHERE GETDATE() BETWEEN A.START AND B.STOP
MARK AS SOLVED if its help you.

REGARDS
MCTS - Shawpnendu bikash maloroy
http://shawpnendu.blogspot.com
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC