Solved

ASP SQL Statement

Posted on 1998-08-10
8
135 Views
Last Modified: 2013-12-25
Is is possible to write a dynamic SQL Statement?
The original statement is simple like == SELECT * FROM Inventory WHERE ID=4 ==.  I tried to change it to == SELECT * FROM Inventory WHERE ID=<% =Number %> == where Number is a local variable that changes according to action.  Please let me know how to make this possible.  Greatly appreciated.
0
Comment
Question by:dangel
  • 3
  • 3
  • 2
8 Comments
 
LVL 4

Accepted Solution

by:
mitek earned 100 total points
ID: 1858930
Yep, of course it's possible.

SQL = "SELECT * FROM Inventory WHERE ID = " & Number

Connection.Execute(SQL)

0
 
LVL 28

Expert Comment

by:sybe
ID: 1858931
Mitek, you posted yopur answer while I was typing it :)
It is abou the same


Yes it is possible

<%
Number = 4

' or if you get the number from a form that has been send

Number = Request.Querystring("number")

strSQL = "SELECT * FROM Inventory WHERE ID = " & Number
Response.write strSQL

If you want to use it to get a recordset

Set RS = Conn.Execute(strSQL)

%>
0
 
LVL 4

Expert Comment

by:mitek
ID: 1858932
SQL is a local variable here.
besides, i wouldn't use Number as a variable name. very confusing and may be conflicting with VB datatypes.

try to use something like snum or the like
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 4

Expert Comment

by:mitek
ID: 1858933
Sorry :)

this once happened to me, too :)))

very funny (wasn't funny for me though, when it happened :)

0
 
LVL 1

Author Comment

by:dangel
ID: 1858934
    Thanks for the help guys.  One more question I need to ask.
     My ASP pages are based on an Access97 database.  I get this error "Database Error: [Microsoft][ODBC Microsoft Access 97 Driver] Data type mismatch in criteria expression." when I try to retrieve data through == Select * from Inventory where ID='%%ID%%' == when ID is set to either AutoNumber or Number.  But I can't change it to Text because it won't work for other pages based on this database.
     What should I do to make it work?  
0
 
LVL 1

Author Comment

by:dangel
ID: 1858935
By the way, '%%ID%%' is submitted from a previous page in a hidden field == <input type="hidden" name="ID" value="<% =IDNUM %>"> where <% =IDNUM %> is a local variable.
0
 
LVL 28

Expert Comment

by:sybe
ID: 1858936
strSQL = "Select * from Inventory where ID=" & Request("ID")
Set RS = Conn.Execute(strSQL)
0
 
LVL 1

Author Comment

by:dangel
ID: 1858937
Thanks for all the help guys.  
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Best practice for a landing page 3 74
Add image to into animation on website template 1 33
ASP.NET MVC 2 40
How to make a good PHP + MySQL + JS pagination system? 3 30
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question