Solved

sql return 0 / null values

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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