Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 21st, 2005, 08:44 PM
Authorized User
 
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default HELP!!! ..Date Range Problem in SQL Server

I new in this forum, but i hope someone expert can help me!

SELECT CustName,address, DateEnter
FROM SalesStatusReport_view
WHERE DateEnter >= '01/06/05' AND DateEnter <= ' 15/06/05'
ORDER BY DateEnter DESC


But the code doesn't work properly, it only return the record within the day range , i.e 01 -15 all come out even the mth and yr is incorrect. So can anyone help me to solve this problem????
Thank you very much!!!

 
Old June 21st, 2005, 11:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Looks like your date format is incorrect. What date format are you using mm/dd/yy or mm/dd/yy?

 
Old June 22nd, 2005, 09:25 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

How about below? (cosidering today's date). Also , try to post exact error message you were receiving.

SELECT CustName,address, DateEnter
FROM SalesStatusReport_view
WHERE DateEnter >= DATEADD(dd,-21,GETDATE()) AND DateEnter <= DATEADD(dd,-6,GETDATE())
ORDER BY DateEnter DESC
 
Old June 23rd, 2005, 06:14 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You have two options. The first one is exactly as you have shown:

SELECT CustName,address, DateEnter
FROM SalesStatusReport_view
WHERE DateEnter >= '01/06/05' AND DateEnter <= '15/06/05'
ORDER BY DateEnter DESC

The second is to use the BETWEEN operator as follows:

SELECT CustName,address, DateEnter
FROM SalesStatusReport_view
WHERE DateEnter BETWEEN '01/06/05' AND '15/06/05'
ORDER BY DateEnter DESC

As someone else suggested, you need to make sure your date format is correct. Is SQL Server set as dd/mm/yyyy or mm/dd/yyyy? You need to check this.

Scott

 
Old June 23rd, 2005, 06:43 PM
Registered User
 
Join Date: Jun 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Pleaser CHECK THE Date Format
As dd/mm/yyyy or the other

 
Old June 28th, 2005, 09:19 PM
Authorized User
 
Join Date: Jun 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for everyone!
YES...The problem is because of the date format is different from the one i use in the sql statement.






Similar Threads
Thread Thread Starter Forum Replies Last Post
INSERT DATE INTO SQL SERVER prasanta2expert ASP.NET 1.0 and 1.1 Basics 1 January 4th, 2007 08:27 AM
How to find a date range between another date rang tayvonne Access 2 August 3rd, 2006 09:50 AM
date in sql server and in visual studio saif44 ASP.NET 2.0 Professional 3 March 22nd, 2006 05:02 PM
Inserting Date in Sql Server lamdog ASP.NET 1.0 and 1.1 Basics 5 March 18th, 2005 01:05 PM
SQL Server Date sankar SQL Server 2000 2 December 19th, 2003 07:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.