Sql query error

I am using this query - frappe.db.sql(‘’’ select sum(qty) from tabPurchase Receipt Item
where item_code = “%s” and purchase_order = “%s” and docstatus = 1 ‘’’ %
(item.item_code,item.purchase_order ))
but showing an error for the item_code name = BRUSH 1’ ( BLACK HAIR)
error msg ------
ProgrammingError: (1064, u’You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'PO-00892" and docstatus = 1' at line 2’)

need help.

I think you need to quote the
docstatus=1 to be docstatus=“1”

Not working…

Sorry - I wasn’t reading it properly… you have wildcards via %s…for these, the equals sign must be changed to LIKE

SELECT SUM(qty) FROM `tabPurchase Receipt Item`
WHERE item_code LIKE '%s' AND purchase_order LIKE '%s' AND docstatus = 1
1 Like