SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 Article: Writing dyanmic SQL in an ASP page
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 07/29/2000 :  16:21:08  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Alejandro writes "Please help me, I can't write the syntax for something like this: search?cat1=America&cat2=EEUU . . . "

Article Link.

Anonymous
Starting Member

0 Posts

Posted - 07/31/2000 :  10:55:43  Show Profile  Reply with Quote
Just to help with the query you have

The correct code would be

MySQL = "SELECT * FROM MiTable WHERE cat1 LIKE '" & Request.QueryString("cat1") & "' AND cat2 LIKE '" & Request.QueryString("cat2") & "'"

In ASP the = Sign must be replaced by LIKE for it to function properly.

Go to Top of Page

mconrath
Starting Member

0 Posts

Posted - 07/31/2000 :  11:14:03  Show Profile  Visit mconrath's Homepage  Reply with Quote
RE:Just to help with the query you have

The "=" sign works fine in ASP, you are building a string for SQL server to interpret, not for the ASP server to interpret.
This will work just fine:
MySQL = "SELECT * FROM MiTable WHERE cat1 = '" & Request.QueryString("cat1") & "' AND cat2 = '" & Request.QueryString("cat2") & "'"

Go to Top of Page

dasiefker
Starting Member

USA
2 Posts

Posted - 12/04/2001 :  10:01:26  Show Profile  Reply with Quote
You could also put this code in a stored procedure and pass the values as parameters. This gives you added security (not transmitting your sql code), and if the sql statement were very long, it also gives added performance.

T-SQL code to create stored procedure
--------------------------------------------------
create proc usp_MiTable
@cat1 varchar(100) = 'default',
@cat2 varchar(100) = 'default' as

SELECT * FROM MiTable
Where cat1 = @cat1
and cat2 = @cat2

go
--------------------------------------------------

VB to execute stored procedure (assuming you're
using ADO, and you have a recordset and connection
object declared already)
--------------------------------------------------
MySQL = "exec usp_MiTable " & _
"'" & Request.QueryString("cat1") & "', " & _
"'" & Request.QueryString("cat2") & "'"
call objRS.open(mysql,objconn)
--------------------------------------------------


Dave <><
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000