Solved

sql return 0 / null values

Posted on 2011-03-05
2
405 Views
Last Modified: 2012-05-11
when running this stored procedure -- its keeps crashing the web-page.

I suspect its because the value is zero -- how do I prevent this from happening (via SQL)
@COSID	       int,
@StartDateTime  datetime,
@FinishDateTime datetime

AS
	DECLARE @table1Value int
	
	SELECT @table1Value = (
			SELECT SUM(ChargeableAmount) 
			FROM [TDRData] 
			WHERE (TransactionKey = 6) AND (COSID =@COSID) 
			  AND (TransactionTime BETWEEN @StartDateTime AND @FinishDateTime))
	
	SELECT TotalValue = @table1Value

Open in new window

0
Comment
Question by:amillyard
[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
2 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 500 total points
ID: 35044974
0 is not the same as null

if its returning null, do "SELECT TotalValue = isnull(@table1Value, 0)"

there's nothing wrong with the code itself from what has been provided. you can always change it to have an output parameter rather than simply selecting a value at the end
@COSID	       int,
@StartDateTime  datetime,
@FinishDateTime datetime,
@TotalValue decimal(19,5) output

AS
	DECLARE @table1Value int
	
	SELECT @table1Value = (
			SELECT SUM(ChargeableAmount) 
			FROM [TDRData] 
			WHERE (TransactionKey = 6) AND (COSID =@COSID) 
			  AND (TransactionTime BETWEEN @StartDateTime AND @FinishDateTime))
	
	SELECT @TotalValue = isnull(@table1Value, 0)

Open in new window


Then, when you call the proc, include an "@TotalValue out" parameter
0
 

Author Closing Comment

by:amillyard
ID: 35044995
derekkromm: mmm, I see ... well, your final advise (scripting related) resolved the issue anyhow !
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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