Win a copy of Functional Reactive Programming this week in the Other Languages 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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic