Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 7th, 2003, 04:16 PM
Authorized User
 
Join Date: Jul 2003
Location: Franklin, Indiana, USA.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default Date Comparison

I am comparing a created date to a result from a database and am unable to get them to agree. Several drop down boxes provide integer values for month/date/year that insert into the database correctly. Before running the insert, I search the DB for a Date value equal to the value about to be inserted and cannot get the comparison to work correctly.

Code Segments:

var Month = new String (Request.Form("Month"));
var Date = new String (Request.Form("Date"));
var Year = new String (Request.Form("Year"));

var InsertDate = Month + "/" + Date + "/" + Year;

SQL = "INSERT INTO NurseryEvent (EventDate, ServiceID) VALUES ('"
SQL = SQL + InsertDate
SQL = SQL + "', "
SQL = SQL + ServiceDescriptionID
SQL = SQL + ")";

adoConnection.Execute(SQL);

Above code works correctly. When I try to add a Select/check function before the insert command, the comparisons fail:

SQL = "SELECT * FROM NurseryEvent ";
SQL = SQL + " WHERE EventDate = " + InsertDate;

RS = adoConnection.Execute(SQL);

EventDate NEVER seems to equal InsertDate

Help!!??

Rich






__________________
Ego is a faithful friend; He stays with us all the way to the crater.
Reply With Quote
  #2 (permalink)  
Old August 8th, 2003, 08:29 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

which db are you using?

Reply With Quote
  #3 (permalink)  
Old August 8th, 2003, 08:40 AM
Authorized User
 
Join Date: Jul 2003
Location: Franklin, Indiana, USA.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Access 2000

Reply With Quote
  #4 (permalink)  
Old August 8th, 2003, 08:46 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this then:

SQL = "SELECT * FROM NurseryEvent ";
SQL = SQL + " WHERE EventDate = #" + InsertDate + "#";



Reply With Quote
  #5 (permalink)  
Old August 8th, 2003, 08:57 AM
Authorized User
 
Join Date: Jul 2003
Location: Franklin, Indiana, USA.
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That fixed the problem.

So I don't beat my head against the wall for 2 days the next time, what do the # signs mean/do and why did the WHERE statement not work until they were there?

Thanks loads for the help!!!

Reply With Quote
  #6 (permalink)  
Old August 8th, 2003, 09:03 AM
Authorized User
 
Join Date: Aug 2003
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

We use # when comparing dates, simply put its similar like the single quote character that we use when we compare strings.

Reply With Quote
  #7 (permalink)  
Old October 20th, 2004, 08:24 PM
Registered User
 
Join Date: Oct 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

how would you do the same thing but in SQL2000?

Reply With Quote
  #8 (permalink)  
Old October 21st, 2004, 09:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

In SQL 2000, you don't have to use # around the date value, just wrap that within single quotes.
Code:
SELECT......
WHERE ColumnName = '2004-10-20'
Cheers!

_________________________
- Vijay G
Strive for Perfection
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 Comparison jroxit Classic ASP Databases 5 October 5th, 2007 05:39 PM
Date comparison problem mat41 Javascript 3 August 30th, 2006 09:22 PM
Date comparison rajuru Beginning PHP 2 February 19th, 2005 10:33 AM
Date comparison lily611 General .NET 5 January 4th, 2005 07:08 AM
Date Comparison cmiller PHP How-To 3 June 19th, 2003 02:58 PM



All times are GMT -4. The time now is 08:17 PM.


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