Click to See Complete Forum and Search --> : Working with ASP and SQL
Nephalim
07-16-2001, 05:11 PM
Hello All: I haven't been on in a LOOOONG time. Anywho, I've been trying to figure out ASP and SQL and have run into this problem. I am trying to write a page that retrieves data from one specific recordset and fills out the page according to that recordset, whichever the user chooses it to be. My method includes a SQL request something like this: ("SELECT * FROM table WHERE variable = x") , where x is the user specified variable. Unfortunately, I can only get it to work if x is instead a string, such as 'x', instead. Can anyone help me here? By the way, variable is the unique key for the table. HELP!
------------------
~ And that is my humble opinion.
When I was a boy I was told that anybody could become President. Now I'm beginning to believe it. - Clarence Darrow
The greatness of a woman’s power is measured in the size and amount of the balls she clutches in hand. -Me
"Tink"
1 GHz Tbird on A7V, 128MB PC133 RAM, Samsung 19" 900IFT, Radeon 64MB DDR VIVO, SB Live! MP3+, 42.9GB IBM HDD, Plexwriter 8/4/32, 3C905CTXM nic, Intellimouse Explorer
Grizzly
07-16-2001, 09:20 PM
I'm not entirely sure I understand your situation from the post above, but this sounds like you're a little new to SQL statements.
If you want to say:
SELECT *
FROM table
WHERE variable = x
And if X is a string (Anything other than a raw digit), than you should have single quotes around x.
Perhaps if you try to either reword your question or give us some more info I can catch your drift a little better :P
Pestilence
07-17-2001, 09:47 AM
To be more technically specific its double quotes on both sides of a single quote and then an & and then the variable and then another & and a single quote with double quotes on each side again. But I use that when I deal with some session variables. And I don;t even know if that would apply either. Grizzly is right in saying you should give us some more details.
------------------
(\__/) See the bunny.
(='.'=) Hear the bunny.
(") (") Pet the bunny.
BE the bunny.
Data Structure programming assignment solutions found here! http://www.sa.sc.edu/cp/java/
By Yours truly.
Nephalim
07-17-2001, 12:38 PM
Much thanks to both of you, though I have figured it out. Nonetheless, just to clarify:
My old statement was:
("SELECT * FROM table WHERE variable = x")
However, Pestilence was correct in his statement:
("SELECT * FROM table WHERE variable = '" & x & "' ")
I have since used the second method, which works... but is there a better way using SQL or just plain VBScript? It is true, I have NEVER used SQL before. There is no time like the present to learn something new!
------------------
~ And that is my humble opinion.
When I was a boy I was told that anybody could become President. Now I'm beginning to believe it. - Clarence Darrow
The greatness of a woman’s power is measured in the size and amount of the balls she clutches in hand. -Me
"Tink"
1 GHz Tbird on A7V, 128MB PC133 RAM, Samsung 19" 900IFT, Radeon 64MB DDR VIVO, SB Live! MP3+, 42.9GB IBM HDD, Plexwriter 8/4/32, 3C905CTXM nic, Intellimouse Explorer
Dengin
07-17-2001, 04:53 PM
Glad you figured it out. Of course, that line won't work if the field is Numeric, then you'd have to lose the single quotes. Nope, that's pretty much it when it comes to ASP and SQL. I recommend you use this method though:
dim strSql
strSql="SELECT * FROM Table WHERE variable =" & x & ""
rs.open strSql, (connectionstring)
That way, you can put a Response.Write strSql before opening the recordset and troubleshoot your SQL statement better.
I also recommend visiting http://www.4guysfromrolla.com , they have a large number of articles on ASP and SQL, as well as a forum that's been helping me out a lot.
------------------
"My other car is also a Porsche"
-------------------------
Abit BH6, rev. 1.01
PIII-750@931
256MB PC133 Crucial RAM
Hercules Prophet 4500
Diamond Monster MX300 w. Vortex 2 v.2048 drivers
DirectX 8.0a