Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Other SQL Server Topics / June 2007

Tip: Looking for answers? Try searching our database.

problem in date comparison

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
navneetkasulkar@gmail.com - 26 Jun 2007 11:42 GMT
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
Dan Guzman - 26 Jun 2007 12:52 GMT
> 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.

Signature

Hope this helps.

Dan Guzman
SQL Server MVP

>I have a problem in this query:
>
[quoted text clipped - 5 lines]
>
> please help me
Roy Harvey - 26 Jun 2007 12:54 GMT
OK, I guess you noticed that you used the same date for both.

What is the datatype of orderdate?

Roy Harvey
Beacon Falls, CT

>I have a problem in this query:
>
[quoted text clipped - 5 lines]
>
>please help me
MikeJ - 26 Jun 2007 18:50 GMT
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

>I have a problem in this query:
>
[quoted text clipped - 5 lines]
>
> please help me
ctotos@gmail.com - 27 Jun 2007 01:53 GMT
On Jun 26, 3:42 am, "navneetkasul...@gmail.com"
<navneetkasul...@gmail.com> wrote:
> I have a problem in this query:
>
[quoted text clipped - 5 lines]
>
> 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
navneetkasulkar@gmail.com - 29 Jun 2007 10:04 GMT
On Jun 26, 3:42 pm, "navneetkasul...@gmail.com"
<navneetkasul...@gmail.com> wrote:
> I have a problem in this query:
>
[quoted text clipped - 5 lines]
>
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.