Subject | Re: [firebird-support] Multiple WHERE clauses |
---|---|
Author | Venus Software Operations |
Post date | 2015-02-25T04:28:44Z |
On 23/02/2015 12:37 pm, 'Leyne, Sean'
Sean@... [firebird-support] wrote:
First, what you need to do is think of each test as returning a true/false result, and then format the tests as follows:
WHERE 1 =
CASE
WHEN (Param <> 0) THEN 1
WHEN (Some OtherTest) THEN 1
WHEN (Yet another Test) THEN 1
ELSE 0
END
Sean
Thanks Sean. I think I have understood the concept.
This gives me my iID = 72 record:
WHERE 1 = CASE
WHEN 72 > 0 AND tDevelopment.iID = 72 THEN 1
WHEN 72 = 0 AND (CAST(tDevelopment.tDT AS DATE) BETWEEN (SELECT US1.dValue
FROM dSetValue('Current Year', 'From') US1)
AND (SELECT US2.dValue
FROM dSetValue('Current Year', 'To') US2)) THEN 1
ELSE 0 END
This one now give me all records for the given date range:
WHERE 1 = CASE
WHEN 0 > 0 AND tDevelopment.iID = 0 THEN 1
WHEN 0 = 0 AND (CAST(tDevelopment.tDT AS DATE) BETWEEN (SELECT US1.dValue
FROM dSetValue('Current Year', 'From') US1)
AND (SELECT US2.dValue
FROM dSetValue('Current Year', 'To') US2)) THEN 1
ELSE 0 END
Kind regards
Bhavbhuti