Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to SQL: IFF function

I have not used access before but I have to convert an access query into SQL so I can write a report in crystal.

The query currently uses the IFF function in its select statement which appears to determine what value will be returned depending on the table's value for a particular column.

So for instance if the value is "CR" it should be returned as "credit" and if it's "NCR" it should be returned as "non-credit"

Can I do something like this in SQL?

like image 681
MxLDevs Avatar asked Apr 20 '26 01:04

MxLDevs


2 Answers

Use a CASE expression.

CASE WHEN SomeColumn = 'CR' THEN 'credit'
     WHEN SomeColumn = 'NCR' THEN 'non-credit'
END
like image 110
Joe Stefanelli Avatar answered Apr 22 '26 15:04

Joe Stefanelli


You can use the CASE statement:

SELECT CASE WHEN [value] = 'CR' THEN 'Credit' WHEN [Value] = 'NCR' THEN 'non-credit' END
like image 26
Lamak Avatar answered Apr 22 '26 15:04

Lamak