Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
vicki
Posting Yak Master
117 Posts |
Posted - 2002-03-25 : 17:05:24
|
| Hi,I am not really familiar with IIf function and here is the query that sent to me from person who generated the query from access and now I need to modify this to make it work in sql but I don't know how, please help me with thisThanks alotIIf([OfficeType]="50",[OHA].[OHARO], IIf([OfficeType]="11",[AREA],[ROCD],IIf(NULL([COLOCOFC].[OWNR_OCD]="",[OTHER].[DCORO],[COLOCOFC].[OWNR_OCD])))as ReportsToOfficeCode |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2002-03-25 : 18:57:03
|
HiI think the CASE statement will help.Something likeSELECT Case OfficeType WHEN 50 THEN OHARO WHEN 11 THEN ROCD ELSE OWNR_OCD END as ReportsToOfficeCode Look up CASE in books online for some more info.Damian |
 |
|
|
davidpardoe
Constraint Violating Yak Guru
324 Posts |
Posted - 2002-03-26 : 04:50:46
|
Just to clarify IIFIIF (expression1,parameter2,parameter3) returns parameter2 if expression1 is true, parameter3 if not. Read IF expression1 THEN parameter2 ELSE parameter3.It is common to nest IIFs, replacing parameter3 with a nested IIF:-IIF (expression1,parameter1, IIF (expression2,parameter2, IIF (expression3,parameter3,parameter4))) Read as:-IF expression1 THEN parameter1ELSE IF expression2 THEN parameter2ELSE IF expression3 THEN parameter3ELSE parameter 4Or the equivalent CASE:-CASE WHEN expression1 THEN parameter1WHEN expression2 THEN parameter2WHEN expression3 THEN parameter3ELSE parameter4ENDIf you have lots to translate you could write a stored procedure to translate them!============================Chairman of The NULL Appreciation Society"Keep NULLs as NULL" |
 |
|
|
khenry
Starting Member
16 Posts |
Posted - 2002-03-26 : 05:42:21
|
It stands for Inline If and is used a lot in M$ Access.Unlike an IF or CASE statement IIF evaluates both result expressions (an IF only evaluates the appropriate result)You are supposed to avoid them like the plague in Access K e i t h H e n r y |
 |
|
|
|
|
|
|
|