Query that returns 0 when no rows

Hi All, I have a query that selects the max id from a table but would like to try to ensure if no rows are available that it return 0 instead of null. I tried this query but it says it is missing a keyword:

select max(case hv_promas_protocol_id when 'null' then '0') as id from hv_protocol_master

Any ideas?
atxmanAsked:
Who is Participating?

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

x
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.

miketobCommented:
Try with this:

select isnull((select max(MyID) from Table ),0) as MaxId

Open in new window

atxmanAuthor Commented:
Thanks for the quick response, I get an error 'ORA-00904: "ISNULL": invalid identifier'
sdstuberCommented:
SELECT NVL(MAX(hv_promas_protocol_id), 0) AS id FROM hv_protocol_master;

or

SELECT COALESCE(MAX(hv_promas_protocol_id), 0) AS id FROM hv_protocol_master;

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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

slightwv (䄆 Netminder) Commented:
Oracle is NVL:

NVL(value,0)
miketobCommented:
Oh Sorry, I thought it was for MSSQL, I'm not very familiar with oracle but try this as slightwv suggests:
select NVL((select max(MyID) from Table ),0) as MaxId

Open in new window

slightwv (䄆 Netminder) Commented:
>>I'm not very familiar with oracle but try this as slightwv suggests:

This isn't Oracle syntax and sdstuber already posted two options that should work.

Oracle needs to select FROM something.  The outer select needs a "from dual" if it was to be used.
sdstuberCommented:
no,  that's not correct syntax either  for oracle

I already posted 2 working examples for oracle syntax above.
atxmanAuthor Commented:
Thanks this is exactly what i needed
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
Oracle Database

From novice to tech pro — start learning today.