I would like my MSSQL statement to return the string ‘multiple’ if multiple jobs are found. If only one job is found, I want to return the value found in job_no
SELECT CASE WHEN COUNT(*) = 1 THEN job_no ELSE 'multiple' END AS Expr1
FROM job_table
WHERE (item_no LIKE '%11012%')
GROUP BY job_no
The above statement doesn’t evaluate the count(*) correctly and returns all the jobs instead of the string ‘multiple’. I believe it is because of the group statement causing it to evaluate each row separately. Without the GROUP BY statement it errors out that it needs an aggregate or group by.
UPDATE:
Looks like I misunderstood the question. If you just need one record in the result set for all jobs this should do the trick: