asptoday_discuss thread: Date Range Queries, ASP, QueryStrings, and SQL 2000
Message #1 by "Jeremy Palmer" <medicalendar@h...> on Wed, 10 Jul 2002 18:14:15
|
|
Hello Everyone,
I have a bit of a problem. I just upgraded my database from Access 2000
to SQL 2000.
When I did this my date range queries stopped working. I even removed
the '#' around the date variables in the SQL.
Let me explain how the page(s) function:
I take two date variables from a form on a web page, and then pass them to
another page as a querystring in the URL. The second page takes the
values from the querystring and passes them into a SQL query.
Here is my SQL statement:
//////////////////////////////////////////////////////////
SELECT strUsername, strBirthday
FROM dbo.tblMemberProfiles
WHERE strBirthday BETWEEN 'varLowRange' AND 'varHighRange'
//////////////////////////////////////////////////////////
varLowRange = Request.QueryString("LowRange")
//This querystring value comes from the form on the first page//
varHighRange = Request.QueryString("HighRange")
//This querystring value comes from the form on the first page//
When I look at the URL querystring on the second page, everything looks
fine. It passes the date in the QueryString correctly.
Important Notes:
-It worked previously when I used Microsoft Access 2000
-The SQL works when I perform the query directly in Enterprise Manager
-The dates are stored in SQL 2000 as a 'datetime' datatype
Does anybody have any ideas? If I can get this working, I will be forever
thankful to the person with a solution.
Jeremy
Message #2 by "Jeremy Palmer" <medicalendar@h...> on Wed, 10 Jul 2002 23:22:21
|
|
Nevermind everybody. I figured it out. If you do a date query in
Microsoft Access, it does not matter which date comes first for example
this query is OK:
Select *
From tblTest
Where dtmDate BETWEEN '8/21/2002' and '8/21/1977'
However in MS SQL you must put the older date first like this:
Select *
From tblTest
Where dtmDate BETWEEN '8/21/1977' and '8/21/2002'
This seems like an interesting quirk between the 2 databases. Anyway I
thought I would share my newly acquired knowledge.
Happy Coding!
|