Wrox Programmer Forums
|
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 July 24th, 2005, 11:18 PM
Authorized User
 
Join Date: Jun 2005
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!

 
Old July 26th, 2005, 12:03 AM
Friend of Wrox
 
Join Date: Nov 2003
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 ...



 
Old July 26th, 2005, 03:42 AM
Registered User
 
Join Date: Jul 2005
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#


 
Old July 27th, 2005, 12:36 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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

 
Old September 7th, 2005, 08:38 PM
Friend of Wrox
 
Join Date: Aug 2004
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....






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





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