Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL equivalent to Oracle's 'NVL'

Posted on 2004-08-04
4
5,684 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

828 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