Solved

sql return 0 / null values

Posted on 2011-03-05
2
408 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 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