Simonp27
Simonp27

Reputation: 143

Combing two SQL where statements in Rails

How do I make both of these WHERE statements be satisfied please?

where("cast(strftime('%d', date) as int) = ?", month)
where("cast(strftime('%Y', date) as int) = ?", year)

Something like:

where("cast(strftime('%d', date) as int) = ?", month) AND
       where("cast(strftime('%Y', date) as int) = ?", year)

I have tried a few ways but can't get it working.

Thanks

Upvotes: 0

Views: 38

Answers (1)

Ilya
Ilya

Reputation: 13487

You can use multiple question marks:

where("cast(strftime('%d', date) as int) = ? 
       AND cast(strftime('%Y', date) as int) = ?", month, year)

Or just use 2 where statements:

where("cast(strftime('%d', date) as int) = ?", month)
.where("cast(strftime('%Y', date) as int) = ?", year)

Upvotes: 1

Related Questions