Convert IIF multiple conditional statement in Microsoft Access Query to IIF conditional statement in SQL Server

How to convert IIF conditional statement in access query to SQL Server query.


Query in MS Access:

Test: IIf([SM1]=True,[SM1],

Thank you for your help.
Queennie LAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That thing is a horror.
It should have never seen the light of day.
These are all Booleans and you are looking for TRUE if any one of them is true

In Access
Test:[SM1] or [SM2] or [SM3] or [SM4] or [SM5] or [SM6] or [SM7] or [SM8]

In SQL Server
([SM1] or [SM2] or [SM3] or [SM4] or [SM5] or [SM6] or [SM7] or [SM8]) as Test

Nested IIFs are a horror, usually easily replaced by Select Case if VBA code is in use or by Switch in queries
SQL Server has a CASE operator as well.
In this case because they are all Booleans, it is simpler.
Queennie LAuthor Commented:
It does not work.
It does not work.
That's not exactly verbose.

You are looking for Test to be True or False?
Is Null permitted in any of the [SMx] fields -- because Null Booleans nullify everything.
Is an error thrown or null returned or an incorrect value returned or does the universe explode when you try it :)
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Queennie LAuthor Commented:

If test is true.

I did this in Access but I don't know what's the logic in SQL.

Thanks again.
Searched CASE syntax would be

            WHEN [SM1] = True THEN [SM1]
                WHEN [SM2] = True THEN [SM2]
                WHEN [SM3] = True THEN [SM3]
                WHEN [SM4] = True THEN [SM4]
                WHEN [SM5] = True THEN [SM5]
                WHEN [SM6] = True THEN [SM6]
                WHEN [SM7] = True THEN [SM7]
                WHEN [SM8] = True THEN [SM8]  
              ELSE False

      END) as Test

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Queennie LAuthor Commented:
That's what I needed.

Thank you for your help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.