Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2011, 02:43 PM   PM User | #1
alex4501
New Coder

 
Join Date: Jun 2011
Posts: 22
Thanks: 3
Thanked 0 Times in 0 Posts
alex4501 is an unknown quantity at this point
Using a Session Variable to Populate a SQL Statement

Hi everyone,

Ok so what I am basically trying to do is this:

sql = "SELECT * FROM LiftPasses WHERE "&Session("QC_GroupType")&"= 'Yes'"
set liftpassDB = doquery(sql)

I have also tried:

If liftpassDB(Session("QC_GroupType")) = "Yes" Then

But with no joy, does anyone knoe if this is a) possible b) where i am going wrong or c) an alternative solution.

What I basically what to do is look at the database, and extract the records where the "GroupType" is set to "Yes" in the database. In order to show results that are correct for that specific group dynamically.

The GroupType is currently stored in a Session Variable.

Thanks in advance.

Alex
alex4501 is offline   Reply With Quote
Old 08-23-2011, 08:40 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,185
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Your SQL looks perfectly reasonable to me, assuming: (1) The value in the session variable really is the name of a field in the table and (2) You really are using a TEXT field of some kind and it really does have some records where the value is 'YES'.

If this is an Access database and if the field in question is a Yes/No field, then the problem is that 'Yes' is never actually stored in such fields. Only from Access-the-program will you ever actually see a value as 'Yes'. From ADO, the field will be a boolean field, having True and False values.

NOTE: True and False are *keywords*. You do *NOT* put apostrophes around them if you use them as such!

If that is the case, just use
Code:
sql = "SELECT * FROM LiftPasses WHERE "&Session("QC_GroupType")&"= True"
or, since comparing to True is really unnecessary,
Code:
sql = "SELECT * FROM LiftPasses WHERE "&Session("QC_GroupType")
But in any case, you maybe should DEBUG to find out if the session value is what you think it is.

So no matter which variant you use, you should be doing
Code:
sql = "SELECT * FROM LiftPasses WHERE "&Session("QC_GroupType")&"= 'Yes'" ' or other variant
Response.Write "<hr>DEBUG SQL: " & sql & "<hr>"
...
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
alex4501 (08-30-2011)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:21 AM.


Advertisement
Log in to turn off these ads.