|
I have a complex SELECT statement and I'm having trouble figuring out a way to add some new logic using CASE. FACTOR and VALUE are column names; '1', '2', 'A', and 'B' are host variables. In code that doesn't work, here's what I want to do: select * from file where {other selection conditions) and case when FACTOR = '1' then VALUE = 'A' when FACTOR = '2' then VALUE in('A','B') else null end and (more selection conditions) In English: If FACTOR is '1', select all records where VALUE is 'A'. If FACTOR is '2', select all records where VALUE is 'A' or 'B' I think I have three choices: figure out how to do to this with a CASE, write a stored procedure to do the logic, or extend the SELECT statement like this: select * from file where {other selection conditions) and FACTOR = '1' and VALUE = 'A' and (more selection conditions) OR {other selection conditions, same as above) and FACTOR = '2' and VALUE = 'B' and (more selection conditions, same as above) Is this a case of "you can't get there from here", or have I made a goofy error, or have I failed to design the solution properly? Thanks, Reeve
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.