How to convert access query IIf([Time_Enroute] Is Not Null,IIf([P.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
How to convert access query IIf([Time_Enroute] Is Not
Null,IIf([Priority_Number]<3,"Code3","Code2" to SQL server compatible query?

Thanks for the help in advance.
Thanks,
Nuthan
 
If statements are allowed in Stored Procedures, so check out Books Online
for the syntax.

Whenever I see expressions like this, it makes me think that there are
fundamental errors in the database. For example, I would think that there
would be a lookup table of Codes and what their priority numbers(or range)
would be. Thus, you could just link the table, and not perform all of this
IIF() hocus pocus. $0.02.
 
Hi,


You can also use a CASE syntax. Preferable to start from a SWITCH -VBA:


SWITCH( condition1, value1, condition2, value2, ..., ...,
true, defaultValue)

that you translate into

CASE WHEN condition1 THEN value1 WHEN condition2 THEN value2 ....
ELSE defaultValue END


T-SQL syntax is much more "verbose" and does not look like a "function" at
all, but it does play exactly the same role (and it is NOT a control of the
FLOW of execution at all, like a SELECT CASE vba statement could be).


So:


CASE WHEN time_enroute Is Null THEN null WHEN priority_number <3
THEN 'Code3' ELSE 'Code2' END


(note that your initial statement is incomplete, so my proposed statement
MAY differ from yours).



Hoping it may help,
Vanderghast, Access MVP
 
Back
Top