Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Ask SQLTeam Question

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.

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

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

Starting Member

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

Where cat1 = @cat1
and cat2 = @cat2


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") & "'"

Dave <><
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000