Case statement with Strings in a SQL statement

25 pts.
Tags:
SQL
SQL statements
I have a SQL statement that DOES work to create a bit of a pivot table.
select JOB#,
sum(CASE when COURSE#=’36’ then MONTHS  end)
as “Training”
from FILE where group by JOB#
However, what I need is instead of showing the sum of the months, I want to show the string field on if it was completed or not. The below does NOT work, so I’m wondering where I’m going wrong with the syntax.  I get the message “Column COURSE# or expression in SELECT list not valid.”
select JOB#,
(CASE when COURSE#=’36’ then COMPLETED  end)
as “Training”
from FILE where group by JOB#


Software/Hardware used:
strsql
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

If you are only looking to count the completed records you need one more condition.

Try something like this

(CASE when COURSE#=’36’ AND FIELDNAME=’string’ then COMPLETED  end)

Replace field name with the field from the table and the string for the completed  string value.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: