开发者

Access to SQL: IFF function

开发者 https://www.devze.com 2023-02-17 17:23 出处:网络
I have not used access before but I have to convert an access query into SQL so I can write a report in crystal.

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?


Use a CASE expression.

CASE WHEN SomeColumn = 'CR' THEN 'credit'
     WHEN SomeColumn = 'NCR' THEN 'non-credit'
END


You can use the CASE statement:

SELECT CASE WHEN [value] = 'CR' THEN 'Credit' WHEN [Value] = 'NCR' THEN 'non-credit' END


In addition to CASE expressions, Oracle database also supports the DECODE() function.

SELECT DECODE(value, 'CR', 'Credit', 'NCR', 'Non-Credit') from table;

There are few cases where it may be useful to use a DECODE() function rather than a CASE expression, but I would recommend sticking with CASE.

0

精彩评论

暂无评论...
验证码 换一张
取 消