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

Brian Cummiskey brian at hondaswap.com
Mon Aug 14 15:46:05 CDT 2006


Casey, that was an example only.  you can nest as many times as you need 
to.  Without seeing your form, I can't be any more specific about how to 
pass in the vars.

> CREATE proc PROCNAME
> (
> @param1 type(x)
> @param2 type(x)
> )
>
> as
> begin
>
> declare @whereString varchar(8000)
> declare @queryString varchar(8000)
>
> if @param1 > ''
>     begin
>        set @whereString = 'xxxxxx LIKE @param1'
>     end
>
> if @param2 > ''
>     begin
>        set @whereString = @whereString  + 'AND zzzzzz LIKE @param2 '
>     end
>
> set @queryString = 'SELECT * FROM table WHERE " + @whereString
>
> exec(@queryString)
>
> end
>
>   




More information about the thelist mailing list