Subject | Re: [firebird-support] WHERE clause inside stored procedure |
---|---|
Author | Helen Borrie |
Post date | 2005-10-17T11:59:08Z |
At 11:52 AM 17/10/2005 +0000, you wrote:
v.1.5 release notes and see whether you can use this to achieve what you want.
./heLen
>Hi all,It won't; but have a close look at the docs of EXECUTE STATEMENT in the
>
>I'd like to use a selectable stored procedure but I need to build a
>dynamic WHERE clause based on input parameters. For instance,
>assuming I have 8 char(1) parameters and 2 of them are 'T', I need
>something like:
>
>select the_field
> from the_table
> where ((some_field = some_integer_1) or (some_field = some_integer_2))
>
>I know I could also do:
>
>select the_field
> from the_table
> where (some_field IN (some_integer_1, some_integer_2))
>
>My question is, can I either build a WHERE clause dynamically from
>within a stored procedure OR can I pass a where clause as a parameter
>to a stored procedure?
>
>My procedure might look like:
>
>create procedure spMyProc(some_bool_1 char(1), some_bool_2 char(1),
>etc...)
> returns (the_result VarChar(30))
>AS
> declare varaible sWhere VarChar(100);
>Begin
> if (some_bool_1 = 'T') then
> Begin
> sWhere = '(some_field = 1)';
> End
> etc, etc, etc...
> for Select some_stuff
> from the_table
> where :sWhere
> into :the_result
> do
> Begin
> suspend;
> End
>End
>
>I don't think this would work, but how can I accomplish the same thing?
v.1.5 release notes and see whether you can use this to achieve what you want.
./heLen