开发者

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?


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜