Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

Weird Session Variable Issue

Posted 05 Apr 2004 06:47:18
1
has voted
05 Apr 2004 06:47:18 Jim Van Scoyk posted:
I have a query that queries a SQL 2000 database. If I put the "date" value that I want to query on in the query it works as planned. If I set the "date" to a session variable that has previously had the same date put in it I only get 8 records. As you can guess I have more than 8 records in it. It doesn't matter what date I put into the session variable I always get 8 records displayed in the page. Once again if I hard code the date into the SQL statement it works fine.
Any Ideas?

Replies

Replied 07 Apr 2004 02:52:19
07 Apr 2004 02:52:19 Phil Shevlin replied:
Are the 8 records random or are they all from the same date? Chances are there is a data type problem. -- Like it reading the session date value as a string !?!

You could also change the session value to the date data type using cDate: www.devguru.com/Technologies/vbscript/quickref/cdate.html
Replied 09 Apr 2004 00:29:40
09 Apr 2004 00:29:40 Jim Van Scoyk replied:
All 8 records are from the same date. I will check the data type.
Thanks!!
Replied 12 Apr 2004 20:48:28
12 Apr 2004 20:48:28 Jim Van Scoyk replied:
I set the data type using cDate and it had no effect on the results of the query. Now I'm really confused.
Replied 12 Apr 2004 21:06:15
12 Apr 2004 21:06:15 Phil Shevlin replied:
can you show your SQl statement here?
Replied 13 Apr 2004 19:21:14
13 Apr 2004 19:21:14 Jim Van Scoyk replied:
Here is what I have:

SELECT ID, pickupdate, total_product, grand_total, verified, check_numb, form_of_payment
FROM dbo.total_purchases
WHERE pickupdate = 'dateselect'
ORDER BY ID ASC

Here is my session variable:
dateselect = Session("datelist"
Replied 14 Apr 2004 17:21:43
14 Apr 2004 17:21:43 Phil Shevlin replied:
This code will print out the SQL statement. Whenever I have problems like you're having, I print the sql then paste it into Query Analyser to test it. This helps me debug my problem.

<pre id=code><font face=courier size=2 id=code> ' set the session to a default value to prevent an error in the SQL
if (Session("datelist" = "" then
Session("datelist" = "01/01/1900"
end if

Dim dateselect
dateselect = Session("datelist"

' Build SQL statement
Dim SQL
SQL = "SELECT ID, pickupdate, total_product, grand_total, verified, check_numb, form_of_payment"
SQL = SQL & " FROM dbo.total_purchases"
SQL = SQL & " WHERE pickupdate = '" & dateselect & "'"
SQL = SQL & " ORDER BY ID ASC"


' print SQL statement for testing
response.Write(SQL)</font id=code></pre id=code>

Reply to this topic