Solved

SQL CASE field WHEN NULL then... not returning data

Posted on 2003-11-06
4
2,339 Views
Last Modified: 2012-06-21
In View SQL statement:

SELECT     TR_ID, TR_Name, TR_Qty, TR_CalcQty, CASE TR_Qty WHEN NULL THEN TR_CalcQty ELSE TR_Qty END AS New_Qty
FROM         dbo.tblTR

this doesn't recognise that records are null

How can I fix this?
0
Comment
Question by:Doozy
[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
4 Comments
 
LVL 58

Accepted Solution

by:
amit_g earned 250 total points
ID: 9698242
SELECT     TR_ID, TR_Name, TR_Qty, TR_CalcQty, IsNull(TR_Qty, TR_CalcQty) AS New_Qty
FROM         dbo.tblTR
0
 
LVL 8

Expert Comment

by:Dishan Fernando
ID: 9698705
0
 
LVL 23

Expert Comment

by:seazodiac
ID: 9699166
if you prefer your original query not to be changed:

try this before you run your query:

SET ANSI_NULLS OFF

go

OR

sp_db_options "<your_database_name>" , "ANSI nulls" , false
go
0
 

Expert Comment

by:synakamr
ID: 14870121
Change:
SELECT     TR_ID, TR_Name, TR_Qty, TR_CalcQty, CASE TR_Qty WHEN NULL THEN TR_CalcQty ELSE TR_Qty END AS New_Qty
FROM         dbo.tblTR

To:
SELECT     TR_ID, TR_Name, TR_Qty, TR_CalcQty, CASE WHEN TR_Qty IS NULL THEN TR_CalcQty ELSE TR_Qty END AS New_Qty
FROM         dbo.tblTR

Detail:
CASE TR_Qty WHEN NULL
CASE WHEN TR_Qty IS NULL
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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 ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

739 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