SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Check for zero of null value in SSRS 2005 in the S
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dbrune
Starting Member

USA
2 Posts

Posted - 10/09/2012 :  13:32:40  Show Profile  Reply with Quote
This is a question that I think is more a problem with SSRS than anything else. I have created a select statement that contains a lot of calculated values that are then grouped for a report and I would like to check for nulls and zeros in the denominator and return a 0 if that is found. I DO NOT want to put it in the Report itself but want to do it in the SQL Select statement. Does anyone know if this is possible and how to do it? Using IF THEN, CASE or other expressions does not seem to work!

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/09/2012 :  14:26:16  Show Profile  Reply with Quote
Either of the following should work:
-- 1
CASE WHEN denomiator = 0 THEN 0 ELSE numerator/denominator AS YourResultColmn

-- 2
COALESCE(numerator/NULLIF(denominator,0),0) AS YourResultColumn
Go to Top of Page

dbrune
Starting Member

USA
2 Posts

Posted - 10/10/2012 :  17:18:22  Show Profile  Reply with Quote
When I use these formulas I am getting the message "invalid or missing expression". I am not writing inline SQL but using the graphical query designer.

CASE WHEN Table1.Field1 = 0 THEN 0 ELSE Table2.Field2 / 1000 * Table1.Field1
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000