|
INTERVIEW QUESTIONS
DATABASE
MS SQL SERVER
DETAILS
Question: How To Replace Given Values with NULL using NULLIF()?
Answer: Sometime you want to hide certain values by replacing them with NULL values. SQL Server offers you a nice function called NULLIF() to do this:
NULLIF(expression, value) -- Returns NULL if "expression" equals to value" -- Returns "expression", otherwise
NULLIF() can be viewed as the reverse function of ISNULL(). The tutorial script below shows you a good example of using NULLIF():
USE GlobalGuideLineDatabase; GO
SELECT id, counts FROM ggl_links; GO
id counts
----------- -----------
101 NULL
102 8
1101 NULL
202 NULL
2101 NULL
2102 NULL
301 NULL
302 NULL
-- converting NULL to 0 UPDATE ggl_links SET counts=ISNULL(counts,0); GO
|
|
|
Category |
MS SQL Server Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 8144 users |
Added on |
9/24/2014 |
Views |
71777 |
Rate it! |
|
|
Question:
How To Replace Given Values with NULL using NULLIF()?
Answer:
Sometime you want to hide certain values by replacing them with NULL values. SQL Server offers you a nice function called NULLIF() to do this:
NULLIF(expression, value) -- Returns NULL if "expression" equals to value" -- Returns "expression", otherwise
NULLIF() can be viewed as the reverse function of ISNULL(). The tutorial script below shows you a good example of using NULLIF():
USE GlobalGuideLineDatabase; GO
SELECT id, counts FROM ggl_links; GO
id counts
----------- -----------
101 NULL
102 8
1101 NULL
202 NULL
2101 NULL
2102 NULL
301 NULL
302 NULL
-- converting NULL to 0 UPDATE ggl_links SET counts=ISNULL(counts,0); GO Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
How To Replace NULL Values in Expressions using ISNULL()?
|
View Answer
|
|
What Happens If NULL Values Are Involved in Boolean Operations?
|
View Answer
|
|
What Happens If NULL Values Are Involved in Comparison Operations?
|
View Answer
|
|
What Happens If NULL Values Are Involved in Bitwise Operations?
|
View Answer
|
|
What Happens If NULL Values Are Involved in Datetime Operations?
|
View Answer
|
|
What Happens If NULL Values Are Involved in String Operations?
|
View Answer
|
|
What Happens If NULL Values Are Involved in Arithmetic Operations?
|
View Answer
|
|
How To Assign NULL Values to Variables or Columns?
|
View Answer
|
|
What Are NULL Values in MS SQL Server?
|
View Answer
|
|
How To Create a Dynamic Cursor with the DYNAMIC Option?
|
View Answer
|
|
How To Create a Scrollable Cursor with the SCROLL Option?
|
View Answer
|
|
How To Declare and Use Cursor Variables?
|
View Answer
|
|
How To Loop through the Result Set with @@FETCH_STATUS?
|
View Answer
|
|
How To Transfer Data from a Cursor to Variables with a "FETCH" Statement?
|
View Answer
|
|
How To Fetch the Next Row from a Cursor with a "FETCH" Statement?
|
View Answer
|
|
How To Execute the Cursor Queries with "OPEN" Statements?
|
View Answer
|
|
How To Declare a Cursor with "DECLARE ... CURSOR" in MS SQL Server?
|
View Answer
|
|
What Are Cursors in MS SQL Server?
|
View Answer
|
|
Can You Create a Logon Trigger in SQL Server 2005 Express Edition?
|
View Answer
|
|
Can You Roll Back the DDL Statement in a Trigger?
|
View Answer
|