Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (20.3k points)

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?

1 Answer

0 votes
by (40.7k points)

Use the CASE expression.

Head over to this video to learn CASE expression in detail:

CASE WHEN Some_Column = 'CR' THEN 'credit'

 WHEN Some_Column = 'NCR' THEN 'non-credit'

END

Refer to this video to understand how  IFF function  works:

Let’s understand how IFF function works:

We can consider IFF function as a combination of IF-ELSE and CASE statements. IFF function accepts 3 arguments which are as follows:

  • Boolean expression is the first argument. This returns either true or false.
  • If the result of the first expression holds ‘true’ then the 2nd argument will result as output otherwise 3rd argument.

Syntax:

IIF (Boolean_Expression, True_Value, Flase_Value)

Example:

SQL IFF query to compare two integers:

SELECT 

IIF(15 > 10, 'TRUE', 'FALSE') AS Result;

In the above example, you can observe that Condition inside IIF function (i.e., 15>10) is TRUE. So, the second argument is returned as output, which is TRUE

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 28, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 10, 2020 in SQL by dev_sk2311 (45k points)
0 votes
1 answer
asked Dec 10, 2020 in SQL by dev_sk2311 (45k points)

Browse Categories

...