Solved

SQL equivalent to Oracle's 'NVL'

Posted on 2004-08-04
4
5,698 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
[X]
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
  • 2
4 Comments
 
LVL 43

Expert Comment

by:Eugene Z
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 43

Accepted Solution

by:
Eugene Z 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

734 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