Reputation: 109
$query = "select (select count(a.serial_no) from tra2 a where a.model_no = ".$id." and a.flag = cast(3 as character varying) + (select count(a.serial_no) from stk a where a.model_no = ".$id." and a.trans_id is NULL)as qty)";
$result = $this->db->query($query);
return $result->result();
When i run the query
ERROR: syntax error at or near "as"
LINE 1: ...ck a where a.model_no = K258 and a.trans_id is NULL)as qty)
Upvotes: 2
Views: 50
Reputation: 10680
The end of the quest must be:
...a.trans_id is NULL)) as qty"
Currently You have some like this
select (select 1 + 2 as qty)
but You want
select (select 1 + 2) as qty
Upvotes: 2
Reputation: 311
Add ''
(quotes) on your WHERE
clauses. I guess the data type is VARCHAR
so you have to use quotes in your query
Like this
.... WHERE a.model_no = '" . $id . "' AND ...
Upvotes: 4