Link to home
Start Free TrialLog in
Avatar of srodgers45
srodgers45

asked on

Make "NULL" returns in a column into a set value

I want to make "NULL" values in a column into a set value such as whenever there is "NULL" it will equal "99" in SQL Server. Is that possible?

Thanks in advance....

The column name is "PCRServer.dbo.PCR.STATUS"
Avatar of Mark Wills
Mark Wills
Flag of Australia image

you can use ISNULL(Field,'99') but the value you want must match the same datatype....

So in your case ...

SELECT  isnull(PCRServer.dbo.PCR.STATUS,'99') as PCR_Status
Avatar of srodgers45
srodgers45

ASKER

Thanks for the help, very much appreciated....
Hello srodgers45

We can use COALESCE(yourcolumnName,'99') to replace the NULL values of the table to value 99 while getting the output.

SELECT othercolumns, COALESCE(PCRServer.dbo.PCR.STATUS,'99') PCR_Status
From yourTable

Read more about the command from - https://docs.microsoft.com/en-us/sql/t-sql/language-elements/coalesce-transact-sql

Vaibhav
FYI, ISNULL and COALESCE are not exactly the same:

ISNULL ( check_expression , replacement_value )   -- useful for a single value/replacement and is T-SQL specific syntax
COALESCE ( expression [ ,...n ] )   -- can evaluate one or more values and then a replacement and is SQL Standard syntax

https://docs.microsoft.com/en-us/sql/t-sql/functions/isnull-transact-sql
https://docs.microsoft.com/en-us/sql/t-sql/language-elements/coalesce-transact-sql
Hello PortletPaul

Yes you are correct but in this specific case they are same. Here we are just checking single column value.

Vaibhav
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.