Solved

ASP SQL Statement

Posted on 1998-08-10
8
126 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
Comment Utility
Yep, of course it's possible.

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

Connection.Execute(SQL)

0
 
LVL 28

Expert Comment

by:sybe
Comment Utility
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
Comment Utility
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
 
LVL 4

Expert Comment

by:mitek
Comment Utility
Sorry :)

this once happened to me, too :)))

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

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:dangel
Comment Utility
    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
Comment Utility
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
Comment Utility
strSQL = "Select * from Inventory where ID=" & Request("ID")
Set RS = Conn.Execute(strSQL)
0
 
LVL 1

Author Comment

by:dangel
Comment Utility
Thanks for all the help guys.  
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to count occurrences of each item in an array.

762 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now