Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SQL quetsion - how to 'convert' null to zero? (if statement)

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
quick question: is there a possibility to return the value 0 and not NULL from the db?

example:
Select empl_id, age from myTable

result:
1 NULL
2 55

I would like to have:
1 0
2 55

thanks for any pointers
[ October 08, 2007: Message edited by: Peter Primrose ]
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
COALESCE(column_name,0)

Select empl_id, COALESCE(age,0)
from myTable


This will regardless RDBMS.
[ October 08, 2007: Message edited by: Paul Campbell ]
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!