[thelist] To Store or Not to Store - Building dynamic queries

Brian Cummiskey brian at hondaswap.com
Mon Aug 14 15:08:39 CDT 2006


> For this phone book search engine site I'm working on, users will have
> the option to search by one or multiple search criteria.  Up to this
> point, I've been putting all queries into a stored procedure.  At this
> point, I'm unsure how to proceed.
>   

The easiest way is to pass in your parameters based on the 
checkboxes/form elements that are used to make a dynamic vairable query.
Note, this is server intensive but shouldn't be a big deal for the 
limited computation you need to do in your case.

CREATE proc PROCNAME
(
@param1 type(x)
@param2 type(x)
)

as
begin


declare @queryString varchar(8000)

if @param1 = 'xxxx'
    begin
       set @queryString = 'SELECT xxxxxx from yyyyyyy where fieldname = 
@param1'
    end

if @param2 = 'yyyy'
    begin
       set @queryString = 'SELECT zzzzzz from yyyyyyy  etc..... '
    end

exec(@queryString)

end



More information about the thelist mailing list