Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Search MSSQL DB using stored procedure

New Here ,
Jul 21, 2008 Jul 21, 2008
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.
TOPICS
Server side applications
231
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 21, 2008 Jul 21, 2008
LATEST
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.
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines