Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL and variables

Status
Not open for further replies.

vlitim

Programmer
Sep 2, 2000
393
GB

I am passing a string called searchterm(MPBDSUP500MUW) to a page below

SKUNo = Request.QueryString("searchterm")
SQL="SELECT * FROM VIPS_Products WHERE SKU='SKUno'AND active=1"
set search=objconn.execute(SQL)

but i always get no results back. If i replace the sql to look like this

SQL="SELECT * FROM VIPS_Products WHERE SKU='MPBDSUP500MUW'AND active=1"

then the correct record is found, can someone please tell me what I am doing wrong!?

cheers!

 
You are not calling the the same variabale as you have declared. You have declared 'SKUNo' but you are trying to call 'SKUno'

I think that is what is wrong anyway

Onward and Upward !


SKUNo = Request.QueryString("searchterm")
SQL="SELECT * FROM VIPS_Products WHERE SKU='SKUno'AND active=1"
set search=objconn.execute(SQL)


 
You should not use the ' delimeter in your statement.
Code:
SQL="SELECT * FROM VIPS_Products WHERE SKU=" & SKUno & " AND active=1"

This will 'dereference' the value of your variable, and should produce the desired results.

hope it helps!:)
Paul Prewett
 
If I do this

SQL="SELECT * FROM VIPS_Products WHERE SKU=" & SKUno & " AND active=1"

I get this error??

Invalid column name 'MPBDSUP500MUW'
 
do a response.write of the sql statement and post the output here... it's strange that it would give that error since that value is on the right side of the = operator???
 
without sounding too stupid! how do you do a response.write of the sql statement?

cheers!?

 
Code:
SQL="SELECT * FROM VIPS_Products WHERE SKU=" & SKUno & " AND active=1"
response.write(SQL)

Just make sure you put the response.write statement before the line where you are getting the error. This will output the value of the string, 'SQL' to the screen so that you can see exactly what's in there.

It's the most effective way (in my humble opinion) to debug asp scripts.

 
Excellent very useful to know, this is what is outputed, though I can't see what is wrong with it

SELECT * FROM VIPS_Products WHERE SKU=MPBDSUP500MUW AND active=1
 
You should put ' around your string. If you don't SQL treats it like a number until it realizes that it isn't.

Try:
SQL="SELECT * FROM VIPS_Products WHERE SKU='" & SKUno & "' AND active=1"

That should output:
SELECT * FROM VIPS_Products WHERE SKU='MPBDSUP500MUW' AND active=1

Also, VBScript is not case sensitive. Harold Blackorby
hblackorby@scoreinteractive.com
St. Louis, MO
 
Give this a shot --
Code:
SQL = "SELECT * FROM VIPS_Products WHERE ((SKU=""" & SKUno & """) AND (active=1))"

That will get your value in quotes (that's good if the value is stored in the db as a string), and we'll just stick in the parentheses for giggles.

let me know how it works:)
 
Excellent, thanks alot everybody using quotes works, I had spent ages trying to figure that out!

Again thanks for all your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top