[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5738
  • Last Modified:

SQL equivalent to Oracle's 'NVL'

What's the SQL Server equivalent to the Oracle 'NVL' function?  
I want to replace a null field with "N/A"
0
natejacobs
Asked:
natejacobs
  • 2
1 Solution
 
Eugene ZCommented:
from http://www.ispirer.com/doc/sqlways36/sqlserver/mssql_fn.html:

COALESCE
Syntax


 COALESCE(expr1 {, exprN })  


COALESCE returns the first expression that is not NULL. The expressions are evaluated in the order in which they are specified. This function is usually used to replace NULL values with a not NULL value.

Example

This example selects title and price for all books. If the price for a given title is NULL, the price shown is 0.00.


SELECT title, COALESCE(price, 0.00) AS price
FROM titles;


Equivalents in other databases

 IBM DB2   COALESCE function  
 Oracle   NVL function  

0
 
Eugene ZCommented:
and replace NULL

 function  ISNULL(price, 'N\A') --replace null wiht 'N\A'
0
 
natejacobsAuthor Commented:
ISNULL!  that's what I was trying to remember
0
 
aaronkempfCommented:
coalesce is a much better answer, since you can pass in 2 or 3 or 12 arguments and it returns the first nonnull
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now