You need to sign in to do that
Don't have an account?
Wm Peck 1958
Can you do a CASE statement in SOQL, like Oracle?
I'm learning all the nuances of SOQL via Workbench, and as you know, it's painful for an Oracle SQL person.
I'm a data analyst, and my goal is to pull Salesforce data into Excel.
I'm just trying to do a case statement in SOQL, such as
case gender
when 'F' then 'Female'
when 'M' then 'Male'
else 'Other'
end
Can this be done in Workbench? I'm told you can't do it, but I need to know for sure, and what are the alternatives.
I asked one of our devleopers, and his response was a switch statement in Apex. I don't think Apex is going to be my tool, plus it's a lot more programm'y than a simple SQL CASE statement.
It looks like Einstein is the way to do this, but I haven't investigated that yet, mainly I'm trying to learn the Data Model and to just pull data. Oracle seemed a lot better in that regard.
Not sure the best topic to choose so just chose "General Development", since there's no SOQL topic.
Thank you.
I'm a data analyst, and my goal is to pull Salesforce data into Excel.
I'm just trying to do a case statement in SOQL, such as
case gender
when 'F' then 'Female'
when 'M' then 'Male'
else 'Other'
end
Can this be done in Workbench? I'm told you can't do it, but I need to know for sure, and what are the alternatives.
I asked one of our devleopers, and his response was a switch statement in Apex. I don't think Apex is going to be my tool, plus it's a lot more programm'y than a simple SQL CASE statement.
It looks like Einstein is the way to do this, but I haven't investigated that yet, mainly I'm trying to learn the Data Model and to just pull data. Oracle seemed a lot better in that regard.
Not sure the best topic to choose so just chose "General Development", since there's no SOQL topic.
Thank you.
Greetings!
Yes,as you already know it is not possible to use CASE in the SOQL query and there is no alternative for this.
As you mentioned you can use APEX to check and then use it in the SOQL.Since you are not willing to use Apex and this can also be done by creating the formula field using the CASE on the fields and use it in the SOQL.
Reference:https://salesforce.stackexchange.com/questions/64384/using-case-in-soql-select-statement
Please mark it as best answer if it helps you to fix the issue.
Thank you!
Regards,
Shirisha Pathuri
All Answers
Greetings!
Yes,as you already know it is not possible to use CASE in the SOQL query and there is no alternative for this.
As you mentioned you can use APEX to check and then use it in the SOQL.Since you are not willing to use Apex and this can also be done by creating the formula field using the CASE on the fields and use it in the SOQL.
Reference:https://salesforce.stackexchange.com/questions/64384/using-case-in-soql-select-statement
Please mark it as best answer if it helps you to fix the issue.
Thank you!
Regards,
Shirisha Pathuri
Thx
I did find this Trailhead (https://trailhead.salesforce.com/content/learn/projects/customize-a-salesforce-object/create-formula-fields), so if you think that's sufficient, just give me the thumbs up. Or additional details if appropriate.
Thanks!