access sql isnull

I have a customers table with an ID, and two fields for phone number: phone_primary and phone_alternate.

I want to create a query. that will pull up ID and phone which could be primary_phone.    However, If primary_phone field has a NULL value, then it should display the phone_alternate instead.     But I don't want a 3 column retrieval, and both phone_primary and phone_alternate.

I'm using Access.   What's the SQL syntax for such?

I thought I should start with ISNULL() and was able to retrieve 0 and -1 (for False), but not sure where to go from there?

Any thoughts?

Who is Participating?
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.

Bill RossProgrammerCommented:

Try this.

Select ID, iif(isnull([phone_primary]),[AlternatePhone],[phone_primary]) AS PhoneNumber FROM  Customers;

The key here is the iif  it has 3 parts separated by a comma.  Paert 1 is the test, part 2 is the true part 3 is the false - so if the phone_primary is null then show the secondary in the column PhoneNumber...



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
Patrick MatthewsCommented:
If you need to substitute another value for a null, you can also use the Nz function:

Select ID, Nz([phone_primary], [AlternatePhone]) AS PhoneNumber FROM  Customers;
hansabenAuthor Commented:
Thanks very much!
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
Query Syntax

From novice to tech pro — start learning today.