Skip to main content
Participant
July 21, 2008
Question

Search MSSQL DB using stored procedure

  • July 21, 2008
  • 1 reply
  • 231 views
I am in the middle of changing our ASP / MSSQL website from using Dreamweaver recordsets to one that uses stored procedures with parameters.

I am stuck on the SQL code for a search function. I have a search page that, depending on what the user inputs, lists all products beginning with, or including the search term or number entered. If for instance someone entered EL or 345, I need the results page to show all products containing EL or 345 etc. I have tried the following, but it brings up every record in the database;

CREATE PROCEDURE ResultPage_sp

AS

SELECT *
FROM tbl_Products
WHERE tbl_Model LIKE '%%'

I also need the stored procedure to have parameters included to tighten up the security of our site. Any help would be much appreciated. The tbl_Model is a field in the tbl_Products DB.
This topic has been closed for replies.

1 reply

Inspiring
July 21, 2008
See below. comments start with --this is a comment

CREATE PROCEDURE dbo.usp_ResultPage_sp --use usp_ for naming of stored
procedures
@SearchParam Varchar(20) --declare your input parameter and datatype
AS
set nocount on -- this reduces overhead and response time
SELECT *
FROM tbl_Products
WHERE tbl_Model LIKE '%@SearchParam%' --use your input parameter here
GO

"Cuthleeds" <webforumsuser@macromedia.com> wrote in message
news:g62ar4$ej7$1@forums.macromedia.com...
>I am in the middle of changing our ASP / MSSQL website from using
>Dreamweaver
> recordsets to one that uses stored procedures with parameters.
>
> I am stuck on the SQL code for a search function. I have a search page
> that,
> depending on what the user inputs, lists all products beginning with, or
> including the search term or number entered. If for instance someone
> entered EL
> or 345, I need the results page to show all products containing EL or 345
> etc.
> I have tried the following, but it brings up every record in the database;
>
> CREATE PROCEDURE ResultPage_sp
>
> AS
>
> SELECT *
> FROM tbl_Products
> WHERE tbl_Model LIKE '%%'
>
> I also need the stored procedure to have parameters included to tighten up
> the
> security of our site. Any help would be much appreciated. The tbl_Model is
> a
> field in the tbl_Products DB.
>