I need to add multiple where statements, linked with AND, but also include
a where statement with several conditions linked by OR
What I want to generate:
SELECT column1, column2 FROM table1
WHERE item_id IN (12345, 23456)
AND account_num = 'ACCT01'
AND (
(from_date IS NULL AND to_date IS NULL)
OR (from_date <= '2019-04-01' AND to_date >= '2019-04-01')
)
Unfortunately, I cannot get the last where statement with OR to function
properly.
Code:
Sequel::Model.db[:table1].select(:column1, :column2)
.where(:item_id => [12345, 23456], :account_num => 'ACCT01')
.where(
[:from_date => nil, :to_date => nil] |
[['from_date <= ?', date], ['to_date >= ?', date]]
)
Which generates:
SELECT column1, column2 FROM table1
WHERE item_id IN (12345, 23456) AND account_num = 'ACCT01'
AND (from_date IS NULL AND to_date IS NULL)
# this should be an OR, not an AND
*AND* (from_date <= '2019-04-01' AND to_date >= '2019-04-01')
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.