Solved

SQL equivalent to Oracle's 'NVL'

Posted on 2004-08-04
4
5,681 Views
Last Modified: 2012-06-21
What's the SQL Server equivalent to the Oracle 'NVL' function?  
I want to replace a null field with "N/A"
0
Comment
Question by:natejacobs
  • 2
4 Comments
 
LVL 42

Expert Comment

by:EugeneZ
ID: 11719799
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
 
LVL 42

Accepted Solution

by:
EugeneZ earned 250 total points
ID: 11719814
and replace NULL

 function  ISNULL(price, 'N\A') --replace null wiht 'N\A'
0
 
LVL 3

Author Comment

by:natejacobs
ID: 11719878
ISNULL!  that's what I was trying to remember
0
 
LVL 1

Expert Comment

by:aaronkempf
ID: 11719966
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question