MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 15th, 2008, 02:11 AM
bodemin bodemin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 6 bodemin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 31 sec
Reputation Power: 0
Datetime Comparison Problem

Hi,
I have a comparison problem. I have table that you can see below. It's like this:
RECTIME1 RECTARIH1
10:00:00 22.10.2007
06:00:00 10.10.2007
03:00:00 13.05.2007

There is no date data in RECTIME1 and there is no time data in RECTARIH1.

I want to query the RECTIME1 column which includes time data. I try
Code:
WHERE RECTIME1 < '10:00:00' AND RECTIME1 > '06:00:00' 
but the query returns nothing. I didnot make the table, somebody did. I am sure that RECTIME1 is datetime (8-bit). What should I do?
Thanks

Reply With Quote
  #2  
Old July 15th, 2008, 03:16 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,917 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 3 Days 15 h 51 m 39 sec
Reputation Power: 279
Quote:
Originally Posted by bodemin
...
There is no date data in RECTIME1 and there is no time data in RECTARIH1. ...
Switch to just one column holding date with time, will make your life much easier (not only for this specific query)

Reply With Quote
  #3  
Old July 15th, 2008, 03:34 AM
bodemin bodemin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 6 bodemin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by pabloj
Switch to just one column holding date with time, will make your life much easier (not only for this specific query)


Thanks for your response. I will switch one column later. But, we have lots of records in this table. I have to make this query. So I need help.

Reply With Quote
  #4  
Old July 15th, 2008, 06:02 AM
NimirRamon NimirRamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 21 NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 17 h 27 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by bodemin
Thanks for your response. I will switch one column later. But, we have lots of records in this table. I have to make this query. So I need help.


Mayhap using the datepart functionality would be good enough for you

WHERE
Datepart(hh,RECTIME1) < 10 AND
Datepart(hh,RECTIME1) >= 6

Reply With Quote
  #5  
Old July 15th, 2008, 06:23 AM
bodemin bodemin is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 6 bodemin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 8 m 31 sec
Reputation Power: 0
Quote:
Originally Posted by NimirRamon
Mayhap using the datepart functionality would be good enough for you

WHERE
Datepart(hh,RECTIME1) < 10 AND
Datepart(hh,RECTIME1) >= 6


Thank you so much.
It works.

PS: I am new at SQL programming. I'm learning...

Reply With Quote
  #6  
Old July 15th, 2008, 07:41 AM
NimirRamon NimirRamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 21 NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 17 h 27 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by bodemin
Thank you so much.
It works.

PS: I am new at SQL programming. I'm learning...


Read up on SQL book online (BoL). The number of Date/time functions available is quite daunting at first, but each is very very useful in the correct circumstances.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Datetime Comparison Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT