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 July 24th, 2005, 11:18 PM
Authorized User
 
Join Date: Jun 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date Problem

Hi,

i would like to ask why i try to collect data within a date range, but it doesnt work properly.
e.g. SELECT A, B, C
     FROM table
     where DateEnt >= Date1 AND DaterEnt <= Date2

But when i try to search it, like '07/14/05', the data come out will included the Yr2004's data, anyone tell me how to solve this problem?
Thanks!

Reply With Quote
  #2 (permalink)  
Old July 26th, 2005, 12:03 AM
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

use convert to convert the string to datetime

where convert(datetime, DateEnt) >= Date1 AND convert(datetime,DaterEnt) <= Date2

I would also suggest using BETWEEN ...



Reply With Quote
  #3 (permalink)  
Old July 26th, 2005, 03:42 AM
Registered User
 
Join Date: Jul 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you may use this sql str
 SELECT A, B, C
     FROM table
     where DateEnt >= #Date1# AND DaterEnt <= #Date2#
or

SELECT A, B, C
     FROM table
     where DateEnt between #Date1# AND #Date2#


Reply With Quote
  #4 (permalink)  
Old July 27th, 2005, 12:36 AM
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

#Date1# is not sql server code. I belive it is VB.

Reply With Quote
  #5 (permalink)  
Old September 7th, 2005, 08:38 PM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also be carefull on how you do date compares if you want say <= "10/05/2005" and the actual date value is 10/05/2005 04:30:00 because MS-SQL always stores times unless you set it to 00:00:00 you won't see that particular record if the data your stored has a time stored with it.

10/05/2005 04:30:00 is not <= 10/05/2005
because whats really being done in the compare is
is (10/05/2005 04:30:00 <= 10/05/2005 00:00:00) and the answer is no....

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
DATE PROBLEM ricespn Classic ASP Basics 3 October 20th, 2006 07:15 AM
Date Problem. rupen Classic ASP Basics 3 June 3rd, 2005 09:58 AM
Date Problem tdaustin Classic ASP Basics 10 August 13th, 2004 01:43 PM
date problem hosefo81 PHP How-To 2 May 26th, 2004 11:12 AM
Date problem Larson VB How-To 2 December 30th, 2003 06:10 PM



All times are GMT -4. The time now is 01:35 AM.


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