Subject | RE: [firebird-support] Where condition by column number |
---|---|
Author | Svein Erling Tysvær |
Post date | 2012-12-01T13:29:34Z |
>Hi, I'm wondering if there's a way to refer columns by number in WHEREHi Leonardo!
>conditions.
>
>I need this because I'm creating a generic method to create where clauses
>for hopefully ANY query, in FreePascal.
>
>I need this:
>
>select col1, col2, colN
>from ...
>join ...
>where
> col1 = condition1, col2 = condition2
>
>But now I need to know the name of the column in advance, and some times
>the column name does refer to a real column, but a CASE statement or a
>COALESCE.
I'm not aware of any way to directly do this, but you could of course do similar things by encapsulating into common table expressions (CTEs):
WITH TMP1(col1, col2, colN) as
(select <case statement or whatever you want>
from ...
join ...)
SELECT * FROM TMP1
WHERE col1 = condition1
AND col2 = condition2
However, I'm uncertain how well this kind of usage will be able to use indexes (of course indexes will be used for JOIN, but not necessarily for WHERE).
HTH,
Set