Subject | Re: [firebird-support] Re: Possible to write this in a way that indices will be used |
---|---|
Author | Ivan Prenosil |
Post date | 2008-05-16T16:28:11Z |
Maya,
sql statement from individual pieces, than the other way, i.e. to break single
statement and remove unwanted parts. E.g. where clause for your original select
DECLARE VARIABLE CMD VARCHAR(1000);
...
CMD = SUBSTRING(
COALESCE(' AND D.SuplCde = ' || ISupplierCode, '') ||
COALESCE(' AND D.WrhseCde = ' || IWarehouseCode, '') ||
COALESCE(' AND D.StkCde = ' || IStockCode, '') ||
CASE WHEN IIncludeInactive = 'Y' THEN '' ELSE ' AND D.IsActve = 'Y'' END FROM 6);
IF (CMD<>'') THEN CMD = ' WHERE ' || CMD;
Ivan
http://www.volny.cz/iprenosil/interbase/
> I'm <deep breath> going to dive in and try doing this regex stuff all inside the stored proc, executingIf you plan to use EXECUTE STATEMENT, than IMHO it is much easier to construct
> it with EXECUTE STATEMENT.
sql statement from individual pieces, than the other way, i.e. to break single
statement and remove unwanted parts. E.g. where clause for your original select
> select blah..,can be "synthesized" quite easily this way
> from MyTable D
> where ((D.SuplCde = :ISupplierCode) or (:ISupplierCode is null))
> and ((D.WrhseCde = :IWarehouseCode) or (:IWarehouseCode is null))
> and ((D.StkCde = :IStockCode) or (:IStockCode is null))
> and ((D.IsActve = 'Y') or (:IIncludeInactive = 'Y'))
DECLARE VARIABLE CMD VARCHAR(1000);
...
CMD = SUBSTRING(
COALESCE(' AND D.SuplCde = ' || ISupplierCode, '') ||
COALESCE(' AND D.WrhseCde = ' || IWarehouseCode, '') ||
COALESCE(' AND D.StkCde = ' || IStockCode, '') ||
CASE WHEN IIncludeInactive = 'Y' THEN '' ELSE ' AND D.IsActve = 'Y'' END FROM 6);
IF (CMD<>'') THEN CMD = ' WHERE ' || CMD;
Ivan
http://www.volny.cz/iprenosil/interbase/