Displaying the returned result of frappe.db.sql in proper way

Hello;

I have a query as following:

     employee_test = frappe.db.sql("""
            select name
            from `tabEmployee` where name like 'EMP/0001'
            """)

And I need to display the employee_test in msgprint but without showing the characters that come with the returned string. Because it appears like following: ((u’EMP/0001’,),) and I need to display only EMP/0001. Is there a way?

Regards
Bilal

please try it with this :

 employee_test = frappe.db.sql("""
            select name
            from `tabEmployee` where name like 'EMP/0001'
            """ , as_dict=True)

Thanks a lot for the kindly help and reply.
Now it is displaying it like this: {‘name’: u’EMP/0001’}.
I have really two questions regarding this point:

  • How I can display only EMP/0001?
  • In case my query was selecting two columns, so it is like below:

employee_test = frappe.db.sql(“”"
select name, prefered_email
from tabEmployee where name like ‘EMP/0001’
“”" , as_dict=True)

The output of format(employee_test) is:
{‘name’: u’EMP/0003’, ‘prefered_email’: u’maher@ghayad.com’}

If I need to deal with prefered_email column only, what I have to write? For example, I need to know the value of the column prefered_email, what should I write?

Regards
Bilal

I resolved it.
If I need to select any field, i will use the following format:
employee_test[0].name or employee_test[1].name

Regards
Bilal

1 Like