Solved

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

Posted on 2003-11-06
4
2,329 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
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:dishanf
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now