Using tuple in frappe.db.sql

Hii everyone,
While fetching data from database sometimes you want to check some conditions like if item in list or not in list.
Here i am filtering those items having warehouse in my list_warehouse. Hope this topic will help you.

items = frappe.db.sql(“select item_name from tabItem where item_group = %s and default_warehouse in (%s) " % (‘%s’,”, “.join([”%s"]*len(list_warehouse))),tuple([group] + list_warehouse),as_dict=1)

2 Likes

hi
what if tuple len =1 it will be (x, ) it might cause sql syntax error i can’t remember !

No join will take care of that