Home | Advertising Info2 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Saturday, April 20, 2024  

  Active InfoActive Info  Display List of Info MembersMemberlist  Search The InfoSearch  HelpHelp
  RegisterRegister  LoginLogin
Classic ASP - Database Issues
 PowerASP Code Help Area : Classic ASP - Database Issues
Subject Info: SQL and between statement A d d  -  P o s tAdd P o s t
Author
Message << Prev Info | Next Info >>
cgauss
Newbie
Newbie


Joined: February/06/2005
Online Status: Offline
Info: 1
Added: February/06/2005 at 1:09pm | IP Logged Quote cgauss

I am trying to pull in some dates from a access database table, but for some reason I am getting unexpected results. 

Instead of the dates between the range I am getting every single date.  Any ideas as to what I am doing wrong?  Im guessing it is something very simple.

Here is the code I am using:

Dim cnn,rst
Dim date1, date2

date1 = CDate(date())
date2 = CDate(date()+30)

set cnn = Server.CreateObject("ADODB.Connection")
Set rst = Server.CreateObject("ADODB.Recordset")
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(strEzDBPath2) ' "../db/ez.mdb"
sqltext = "SELECT * FROM tblCalendar WHERE " & CDATE(date) & " BETWEEN " & date1 & " AND " & date2 &""
set rst = cnn.Execute(sqltext)
Response.Write rst("Date")

if not rst.EOF then 'just added
while not rst.EOF

Response.Write rst("Date")

rst.movenext
wend
end if
rst.close
cnn.close

Back to Top View cgauss's Profile Search for other info by cgauss
 
ThePriest
Newbie
Newbie
Avatar

Joined: February/16/2005
Location: South Africa
Online Status: Offline
Info: 2
Added: February/16/2005 at 7:20am | IP Logged Quote ThePriest

Try:
sqltext = "SELECT * FROM tblCalendar WHERE date >= " & date1 & " AND date <= " & date2

Back to Top View ThePriest's Profile Search for other info by ThePriest
 
firas_TheGeek
Newbie
Newbie
Avatar

Joined: May/27/2006
Location: Oman
Online Status: Offline
Info: 28
Added: May/27/2006 at 10:02am | IP Logged Quote firas_TheGeek

first you have to change the field name in the database from Date to sometihng else

because the word date is reserved for the system so when u use it the server will conflict thinking that date is a function to show the date and doesnt know that you mean the field name

second the syntax for the between is

SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2
so after the word WHERE must be a column_Name not the date or the field date
 
try thant and should work
 
Best Regards


__________________
Firas S Assaad (TheGeek)
firas489@gmail.com
0096892166434
http://firas-thegeek.blogspot.com
Back to Top View firas_TheGeek's Profile Search for other info by firas_TheGeek Visit firas_TheGeek's Homepage
 

If you wish to make a comment to this info you must first login
If you are not already registered you must first register

  A d d  -  P o s tAdd P o s t
Printable version Printable version

Info Jump
You cannot add new info in this area
You cannot add to info in this area
You cannot delete your info in this area
You cannot edit your info in this area
You cannot create polls in this area
You cannot vote in polls in this area

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2024 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages ASP programs help tutorial tutorials routine routines jobs listserve mailinglist bulletin board bulletin boards programming snippet snippets CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspprotect.com, www.cjwsoft.com,www.aspclassifieds.com,www.aspphotogallery.com