Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Using variables in SELECT FROM WHERE
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Using variables in SELECT FROM WHERE

 Post Reply Post Reply Page  12>
Author
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Topic: Using variables in SELECT FROM WHERE
    Posted: 24 March 2005 at 2:59pm

Can anyone help me with syntax on the strSQL = line? I've tried putting the variable between ' ' and " ".

Dim strWherel
Dim strSearchl

Set strWhereval = "a"
Set strSearchva = "hello"

strSQL = "SELECT a, b, c, FROM x WHERE strWhere LIKE strSearch;"

Thanks!

Back to Top
bootcom View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
Post Options Post Options   Thanks (0) Thanks(0)   Quote bootcom Quote  Post ReplyReply Direct Link To This Post Posted: 24 March 2005 at 3:29pm
Originally posted by reverett reverett wrote:

Can anyone help me with syntax on the strSQL = line? I've tried putting the variable between ' ' and " ".

Dim strWherel
Dim strSearchl

Set strWhereval = "a"
Set strSearchva = "hello"

strSQL = "SELECT a, b, c, FROM x WHERE strWhere LIKE strSearch;"

Thanks!

 
Aye, try this, dont forget that the SQL line is like a response write line, so if your throwing ASP variables in there dont forget to close of the line and include the ASP stuff Big smile. If your doing it with numbers/boolean values then knock off the '' s .... like this "& strWhere &"
 
strSQL = "SELECT a, b, c, FROM x WHERE '"& strWhere &"' LIKE '"& strSearch &"';"
Back to Top
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 1:43am
Thanks for the feedback. I tried your example. Here is the exact code I'm working on and the result when displayed:
 
strSQL = "SELECT ext.ext, ext.first, ext.last, ext.dept, ext.loc FROM ext WHERE '"& strWhere &"' LIKE '"& strLike &"' ORDER BY '"& strOrder &"';"
Response.Write strSQL
 
SELECT ext.ext, ext.first, ext.last, ext.dept, ext.loc FROM ext WHERE 'ext.last' LIKE 'e%' ORDER BY 'ext.last';
The values being in ' ' cause strange things to happen. Do you know what I need to change to have Response.Write display:
 
SELECT ext.ext, ext.first, ext.last, ext.dept, ext.loc FROM ext WHERE ext.last LIKE 'e%' ORDER BY ext.last;
 
Thanks again!
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 9:15am
try
strSQL = "SELECT ext.ext, ext.first, ext.last, ext.dept, ext.loc FROM ext WHERE "& strWhere &" LIKE '%"& strLike &"%' ORDER BY "& strOrder &";"
Back to Top
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 10:17am

I made the changes you suggested. It didn't like the added % in LIKE '%"& strLike &"%' but the other two changes did the trick:

strSQL = "SELECT ext.ext, ext.first, ext.last, ext.dept, ext.loc FROM ext WHERE "& strWhere &" LIKE '"& strLike &"' ORDER BY "& strOrder &";"

Response.Write strSQL
 
Results in:
 
SELECT ext.ext, ext.first, ext.last, ext.dept, ext.loc FROM ext WHERE ext.first LIKE 'e%' ORDER BY ext.first;
Thank you very much dj!
Back to Top
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 12:24pm

Another question related to the same project? Can you help me with syntax on:

variable = rsObject("fieldname")
 
Catch is, I don't want to set the variable to the value of rsObject("fieldname"), I'm trying to set it to hold the actual text rsObject("fieldname")
 
If I were to:
 
Response.Write variable
 
The display would be:
 
rsObject("fieldname")
 
I've a few different things with no luck.
 
Thanks!
Back to Top
dj air View Drop Down
Senior Member
Senior Member
Avatar

Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj air Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 1:27pm
is this a set field name or dependant on something.

for example

first time it maybe last, second time it may be first etc.


have this is an example of your idea.

i have 2 fields called  called First and Last

on the first time you want to get rsObject("First") and the 2nd you want  rsObject("last")

to be show as the above.

to be suire i need to now how you are using this info.. for example if a querystringvalue = "1" its using the first

else if using "2" its using Last

etc.

Back to Top
reverett View Drop Down
Newbie
Newbie


Joined: 19 March 2005
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote reverett Quote  Post ReplyReply Direct Link To This Post Posted: 25 March 2005 at 2:07pm
Thanks dj. I was able to solve the first issue by using:
 
    'Set Position in Table
    If strSearchby = "first" Then
      strDesc1 = "First"
      strDesc2 = "Last"
      strDesc3 = "Ext"
      strField1 = "rsObject('first')"
      strField2 = "rsObject('last')"
      strField3 = "rsObject('ext')"
        ElseIf strSearchby = "last" Then
          strDesc1 = "Last"
          strDesc2 = "First"
          strDesc3 = "Ext"
          strField1 = "rsObject('last')"
          strField2 = "rsObject('first')"
          strField3 = "rsObject('ext')"
        ElseIf strSearchby = "ext" Then
          strDesc1 = "Ext"
          strDesc2 = "First"
          strDesc3 = "Last"
          strField1 = "rsObject('ext')"
          strField2 = "rsObject('first')"
          strField3 = "rsObject('last')"
    End If
 
But...
 
When I use the following to display the table:
 
'Display recordsets in table
      Response.Write "<TR>"
      Response.Write "<TD><FONT COLOR='#000066' FACE='arial' SIZE='2'>" & strField1 & "</FONT></TD>"
      Response.Write "<TD><FONT COLOR='#000066' FACE='arial' SIZE='2'>" & strField2 & "</FONT></TD>"
      Response.Write "<TD><FONT COLOR='#000066' FACE='arial' SIZE='2'>" & strField3 & "</FONT></TD>"
      Response.Write "<TD>" & "<FONT COLOR='#000066' FACE='arial' SIZE='2'>" & rsObject("dept") & "</FONT>" & "</TD>"
      Response.Write "<TD>" & "<FONT COLOR='#000066' FACE='arial' SIZE='2'>" & rsObject("loc") & "</FONT>" & "</TD>"
      Response.Write "</TR>"
 
The result is:
 
Last First Ext Department Location
rsObject('last') rsObject('first') rsObject('ext') Dept Location
rsObject('last') rsObject('first') rsObject('ext') Dept Location
 
I need to change the table code so it displays the actual data. I beleive it to be another syntax issue.
 
 
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.