Priska Aprilia
Priska Aprilia

Reputation: 1149

CodeIgniter: Case in where clause

How do we state the case in where clause condition in CodeIgniter's active record?

Here is the query I want to achieve

SELECT * FROM table WHERE idx =5342 and CASE WHEN reserve_date = 20151130 THEN reserve_time > 1537 ELSE reserve_date > 20151130 END

I tried to search on Google about this question but still could not find any answer.

Upvotes: 4

Views: 4549

Answers (1)

Saty
Saty

Reputation: 22532

You can write your condition in where clause

$this->db->select("*");
$this->db->where("idx",5342);
$this->db->where("CASE WHEN reserve_date = 20151130 THEN reserve_time > 1537 ELSE reserve_date > 20151130 END");
$query=$this->db->get("table");

Upvotes: 4

Related Questions