Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 21st, 2005, 08:44 PM
Authorized User
 
Join Date: Jun 2005
Location: , , .
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!!!

Reply With Quote
  #2 (permalink)  
Old June 21st, 2005, 11:23 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
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?

Reply With Quote
  #3 (permalink)  
Old June 22nd, 2005, 09:25 AM
Friend of Wrox
 
Join Date: Jan 2004
Location: , , USA.
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
Reply With Quote
  #4 (permalink)  
Old June 23rd, 2005, 06:14 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Location: Wellington, FL , USA.
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

Reply With Quote
  #5 (permalink)  
Old June 23rd, 2005, 06:43 PM
Registered User
 
Join Date: Jun 2005
Location: GuangZhou, , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

Reply With Quote
  #6 (permalink)  
Old June 28th, 2005, 09:19 PM
Authorized User
 
Join Date: Jun 2005
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:11 PM.


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