Last post Mar 06, 2012 07:54 AM by Chen Yu - MSFT
Feb 29, 2012 03:46 PM|msharia|LINK
Hi everyone. I'm currently a CIS
student working on a project for my final class. I'm developing a website
using .asp and am having difficulty with a certain page on my site. This page handles retrieving product information from my database and posting it. This is the code I am using currently and it works fine but its basically a scale down version of what I want
it to do.
' Get the Product ID
productID = TRIM( Request( "pid" ) )
' Get product category
category = TRIM( Request("cat") )
' Open the
Set Con = Server.CreateObject( "ADODB.Connection" )
SOURCE=; DATABASE=; USER ID=; PASSWORD=;"
' Get the Product Information
sqlString = "SELECT * FROM Product "
sqlString = sqlString & "WHERE product_id=" & productID
Set RS =
Server.CreateObject( "ADODB.Recordset" )
RS.ActiveConnection = Con
' Get Current Category
cat = RS( "product_type" )
The area I am having issue with is in Getting the product information. What I am trying to do is get product information off of the product table and other tables that would correspond to the product_type(category) . Currently the Product types are Book, DVD,
Game. For example if cat = 1 (DVD) i want to post Title, studio, director and if cat=2(book) i want to post the ISBN, author, etc.
What I think I should do is use an IF statment here like this
IF cat = 1
select ___, ___, __
from product join dvd __
IF cat = 2
select __, __, __
from ____ ___ __
First off is this the right approach to solving this issue? Second and the part that I am stuck on is how I would implement this. What I mean by this is Im not sure how exactly to code this in asp. Particularly how I would reference what Category is being selected.
My database is also in MS SQL 2008
advance for any and all pointers
I know these forums usually have set procedures in posting code etiquette, excuse me if I posted this incorrectly.
Feb 29, 2012 04:00 PM|Dan Bracuk|LINK
I think the best plan is for you to learn how to select data from more than one table. I've heard good things about the book, Teach Yourself SQL in 10 Minutes by Ben Forta.
Mar 06, 2012 07:54 AM|Chen Yu - MSFT|LINK
From your description, you could use Dynamic SQL in your project. Get your categary_type and select columns from sql query , then set them to temp parameters, execute your dynamic SQL return the final result.
If the problem still here, please post your table structure. It will provide us more information about your problem.
Here is blog about Dynamic SQL :