dbTalk Databases Forums  

problem in date comparison

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss problem in date comparison in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
navneetkasulkar@gmail.com
 
Posts: n/a

Default problem in date comparison - 06-26-2007 , 05:42 AM






I have a problem in this query:

select order from ordertable
where orderdate >= '06/20/2007' and orderdate < '06/21/2007'

this query do not return any record
although there are records in the table matching the query

please help me


Reply With Quote
  #2  
Old   
Dan Guzman
 
Posts: n/a

Default Re: problem in date comparison - 06-26-2007 , 06:52 AM






Quote:
select order from ordertable
where orderdate >= '06/20/2007' and orderdate < '06/21/2007'
I would expect this query to work if the orderdate column is a datetime data
type (although format 'yyyymmdd' is preferred since it is unambiguous). In
the case of char or varchar, string comparison rules are used instead so you
might not get the results you expect.

--
Hope this helps.

Dan Guzman
SQL Server MVP

<navneetkasulkar (AT) gmail (DOT) com> wrote

Quote:
I have a problem in this query:

select order from ordertable
where orderdate >= '06/20/2007' and orderdate < '06/21/2007'

this query do not return any record
although there are records in the table matching the query

please help me



Reply With Quote
  #3  
Old   
Roy Harvey
 
Posts: n/a

Default Re: problem in date comparison - 06-26-2007 , 06:54 AM



OK, I guess you noticed that you used the same date for both.

What is the datatype of orderdate?

Roy Harvey
Beacon Falls, CT

On Tue, 26 Jun 2007 10:42:30 -0000, "navneetkasulkar (AT) gmail (DOT) com"
<navneetkasulkar (AT) gmail (DOT) com> wrote:

Quote:
I have a problem in this query:

select order from ordertable
where orderdate >= '06/20/2007' and orderdate < '06/21/2007'

this query do not return any record
although there are records in the table matching the query

please help me

Reply With Quote
  #4  
Old   
MikeJ
 
Posts: n/a

Default Re: problem in date comparison - 06-26-2007 , 12:50 PM



Looking at ur dates the 2nd part of the and >= should and will only have
items
before 06/21 because time is involved so 06/21/2007 is as of midnite on the
20th
you mite wanna make 06/21/2007 to 06/22/2007 and you should get everything
upto midnite
on the 21st
MJ

<navneetkasulkar (AT) gmail (DOT) com> wrote

Quote:
I have a problem in this query:

select order from ordertable
where orderdate >= '06/20/2007' and orderdate < '06/21/2007'

this query do not return any record
although there are records in the table matching the query

please help me




Reply With Quote
  #5  
Old   
ctotos@gmail.com
 
Posts: n/a

Default Re: problem in date comparison - 06-26-2007 , 07:53 PM



On Jun 26, 3:42 am, "navneetkasul... (AT) gmail (DOT) com"
<navneetkasul... (AT) gmail (DOT) com> wrote:
Quote:
I have a problem in this query:

select order from ordertable
where orderdate >= '06/20/2007' and orderdate < '06/21/2007'

this query do not return any record
although there are records in the table matching the query

please help me
1. Make sure that the data is set to datetime or smalldatetime
2. Select order from ordertable
where orderdate >= '2007-06-20' and orderdate < '2007-06-21'

or to change the date format with:
SET DATEFORMAT mdy;
then do the query.

See: http://www.sqlhacks.com/index.php/Dates/SearchForDates
for details and explanations

Also new this week:

How to search date fields in Microsoft SQL Server
How to deal with quotes in literals with Microsoft SQL Server
How does case sensitiveness affect searches on Microsoft SQL Server
Effect of concatenation on Microsoft SQL Server
Which operator to use for better performance when using Microsoft SQL
Server
How to improve the union queries on Microsoft SQL Server
How many duplicates do I have in the database on an MS SQL Server
How to summarize data with Microsoft SQL Server
How to optimize Microsoft SQL Server
How to retrieve data with Microsoft SQL Server
How to drop the time portion of a DateTime column in MS SQL Server
How to get both the details and the subtotals with Microsoft SQL
Server
How to calculate grand totals with SQL Server with the GROUP BY WITH
ROLLUP






Reply With Quote
  #6  
Old   
navneetkasulkar@gmail.com
 
Posts: n/a

Default Re: problem in date comparison - 06-29-2007 , 04:04 AM



On Jun 26, 3:42 pm, "navneetkasul... (AT) gmail (DOT) com"
<navneetkasul... (AT) gmail (DOT) com> wrote:
Quote:
I have a problem in this query:

select order from ordertable
where orderdate >= '06/20/2007' and orderdate < '06/21/2007'

this query do not return any record
although there are records in the table matching the query

please help me
Hi friends

Thanks for your reply

the problem is solved
i change the datatype of the column to 'datetime' from 'varchar'
and it works
thanx once again
and have a nice day



Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.