Equivalent in MS Sql
-
What is equivalent of MS Access IFF in MS Sql for this expression
IIf([ID_SECTION]=1,1,IIf([ID_SECTION]=2,2,IIf([ID_SECTION]=3,[ID_Tariff_Gender],0)))
Will it be like
CASE WHEN [ID_SECTION]=1 THEN 1
ELSE
CASE WHEN [ID_SECTION]=2 then 2
ELSE
CASE WHEN [ID_SECTION] = 3 then [ID_Tariff_Gender] ELSE 0 END
END
ENDIs it correct ? Any comments !!
-
What is equivalent of MS Access IFF in MS Sql for this expression
IIf([ID_SECTION]=1,1,IIf([ID_SECTION]=2,2,IIf([ID_SECTION]=3,[ID_Tariff_Gender],0)))
Will it be like
CASE WHEN [ID_SECTION]=1 THEN 1
ELSE
CASE WHEN [ID_SECTION]=2 then 2
ELSE
CASE WHEN [ID_SECTION] = 3 then [ID_Tariff_Gender] ELSE 0 END
END
ENDIs it correct ? Any comments !!
If you want to use a SQL
CASE
statement, then try the following:CASE [ID_SECTION]
WHEN 1 THEN 1
WHEN 2 THEN 2
WHEN 3 THEN [ID_Tarriff_Gender]
ELSE 0
END -
What is equivalent of MS Access IFF in MS Sql for this expression
IIf([ID_SECTION]=1,1,IIf([ID_SECTION]=2,2,IIf([ID_SECTION]=3,[ID_Tariff_Gender],0)))
Will it be like
CASE WHEN [ID_SECTION]=1 THEN 1
ELSE
CASE WHEN [ID_SECTION]=2 then 2
ELSE
CASE WHEN [ID_SECTION] = 3 then [ID_Tariff_Gender] ELSE 0 END
END
ENDIs it correct ? Any comments !!
-
Hum Dum wrote:
Is it correct ?
Yes, it works.
Hum Dum wrote:
Any comments !!
In this case,
CASE
is an overkill and anIF
statement works perfectly well. -
Hum Dum wrote:
Is it correct ?
Yes, it works.
Hum Dum wrote:
Any comments !!
In this case,
CASE
is an overkill and anIF
statement works perfectly well.Shameel wrote:
In this case,
CASE
is an overkill and anIF
statement works perfectly well.As a general statement I disgree with that. The IF is an acceptable alternative if CASE didn't exist but CASE exists specifically to deal with situations exactly like that. Given your statement what situation would be correct for CASE then?
-
Shameel wrote:
In this case,
CASE
is an overkill and anIF
statement works perfectly well.As a general statement I disgree with that. The IF is an acceptable alternative if CASE didn't exist but CASE exists specifically to deal with situations exactly like that. Given your statement what situation would be correct for CASE then?
If you see the example, each nested CASE statement has only one WHEN clause, and this is where I recommended an IF clause which works exactly the same way and is more readable. There are, of course, situations where only CASE can be used and an IF cannot be used, like for example, in a SELECT statement.
-
If you see the example, each nested CASE statement has only one WHEN clause, and this is where I recommended an IF clause which works exactly the same way and is more readable. There are, of course, situations where only CASE can be used and an IF cannot be used, like for example, in a SELECT statement.
-
If you see the example, each nested CASE statement has only one WHEN clause, and this is where I recommended an IF clause which works exactly the same way and is more readable. There are, of course, situations where only CASE can be used and an IF cannot be used, like for example, in a SELECT statement.
-
Shameel wrote:
If you see the example, each nested CASE statement..,
Your statement wasn't clear but is still incorrect. For the example given it is misusing CASE. The correct solution is to use it correctly.
-
jschell wrote:
The correct solution is to use it correctly.
Most of our imports come from abroad! :laugh: