Hi all,
I'm currently building a search engine function for a site I'm working on. The search form has 6 inputs that will serve as variables in my SQL statement(ie; userName, country, region, etc.). Any combination of these can be chosen at a time.
In order to not have to build a method and stored procedure for every combination of these 6 fields, I'd like to build my WHERE clause in my form processing page, then send the string to a storedProc as an input variable.
Something like this:
SQLServer(2000) doesn't like this syntax, so I'm looking for the correct syntax for doing this, or possibly another method of achieve this same goal. Also, I don't want to have to create my (entire)SQL string in the frontend and end up having to send it in the command.
As my statement is above, it will work whether all variables are submitted or none at all. I just can't figure out how to read the @WhereString as part of the SELECT statement.
Thanks,
Ryan
I'm currently building a search engine function for a site I'm working on. The search form has 6 inputs that will serve as variables in my SQL statement(ie; userName, country, region, etc.). Any combination of these can be chosen at a time.
In order to not have to build a method and stored procedure for every combination of these 6 fields, I'd like to build my WHERE clause in my form processing page, then send the string to a storedProc as an input variable.
Something like this:
Code:
CREATE PROCEDURE spStoredProc
(
@WhereString ntext
)
AS
SET NOCOUNT ON
SELECT * FROM <dataTable> + @WhereString
SQLServer(2000) doesn't like this syntax, so I'm looking for the correct syntax for doing this, or possibly another method of achieve this same goal. Also, I don't want to have to create my (entire)SQL string in the frontend and end up having to send it in the command.
As my statement is above, it will work whether all variables are submitted or none at all. I just can't figure out how to read the @WhereString as part of the SELECT statement.
Thanks,
Ryan