Jump to content

Call Field From Variable


TBC

Recommended Posts

I have an application where I need to modify the select statement in the recordset based on a variable in the url or another recordset and I'm curious as to if there is a tutorial out there that might walk me through the process.BasicallySelect FIELDNAME from DATABASE Where FIELDNAME = URLVARIABLE (or value from another recordset)TIA/TBC

Link to comment
Share on other sites

Not enough detail was provided to give a more definitive answer, but the basic premise of a SELECT depending on precedent variables is done all the time. The issue is, where does the variable reside in relation to the page that processes the query.If it came from a form POST'ed to the query page it would be WHERE fieldname='::posted_variable::' #....# for dates, etc.If it was computed on the page, then a straight variable call WHERE fieldname=" & posted_variable & "If it is coming out of one database and into another, where the query variable is in the recordset return of the first, set the first recordset return equal to some page variable then use option 2. OR you may be able to link the tables in a SQL that calls both.This give you any ideas? If you provide some specifics, someone may be able to be of more help.

Link to comment
Share on other sites

Not enough detail was provided to give a more definitive answer, but the basic premise of a SELECT depending on precedent variables is done all the time. The issue is, where does the variable reside in relation to the page that processes the query.If it came from a form POST'ed to the query page it would be WHERE fieldname='::posted_variable::' #....# for dates, etc.If it was computed on the page, then a straight variable call WHERE fieldname=" & posted_variable & "If it is coming out of one database and into another, where the query variable is in the recordset return of the first, set the first recordset return equal to some page variable then use option 2. OR you may be able to link the tables in a SQL that calls both.This give you any ideas? If you provide some specifics, someone may be able to be of more help.
Thanks a bunch for the reply, and yes it did give me some ideas. As far as where the variable is coming from it would be from a url parameter but I actually need to select the field that matches the variable in the querystring.SELECT Fieldname FROM table WHERE Fieldname = Request.QueryString("urlvariable")Maybe that makes better sense. I was thinking that if it could be done it would have to be in function or a sub routine but I still seem to be missing it.I hadn't seen this before so I'll play with it a bit. I was thinking that I would need to create a function or a subroutine.Thanks again
Link to comment
Share on other sites

I have a few db pages that have SQL statements that are either pulling the information from the URL or from a form that has been posted. Below is a snippet of code that builds up the SQL statement in a simple telephone list page.

strSQL = "SELECT * FROM ext WHERE Ext > '0'"if len(request("text1")) > 0 then strSQL = strSQL & " AND ([Owner Surname] LIKE '%" & replace(request("text1"),"'","''") & "%' OR [Owner Initials] LIKE '%" & replace(request("text1"),"'","''") & "%') "strSQL = strSQL & " ORDER by Ext ASC"
My more complex telephone list page has similar code but has many more form fields
strSQL = "SELECT * FROM ext WHERE Ext <> '0'"if len(request("select1")) > 0 then strSQL = strSQL & " AND " & request("select1") & " LIKE '%" & replace(request("text1"),"'","''") & "%' "if len(request("select2")) > 0 then strSQL = strSQL & request("bool1") & " " & request("select2") & " LIKE '%" & replace(request("text2"),"'","''") & "%' "if len(request("sort1")) < 1 then strSQL = strSQL & " ORDER by [Owner Surname]"else strSQL = strSQL & " ORDER by " & request("sort1")end ifif len(request("order")) > 0 then strSQL = request("order")If Request.QueryString("fave") = "true" Then strSQL = Request.Cookies("home")("mylist")' & " ORDER by [Owner Surname]"
For examples of SQL statements see the SQL section of this forum.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...