Divide By Zero Error Encountered In Asp.net
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Divide by zero error encountered up vote 2 down vote favorite I'm having an divide by zero error when I launch this SQL query : SELECT CONVERT(VARCHAR(11),CaptureTime,106) 'CaptureTime', Type, CASE WHEN Unit='g/L' THEN (data1* 0.02586) ELSE data1 END As data1, CASE WHEN Unit='g/L' THEN nullif(data2* 0.02586,0) ELSE data2 END As data2, CASE WHEN Unit='g/L' THEN nullif(data3* 0.02586,0) ELSE data3 END As data3, CASE WHEN Unit='g/L' THEN nullif(data1* 0.02586,0) / nullif(data2* 0.02586,0) ELSE (data1/data2) END As Ratio, CASE WHEN Unit='g/L' THEN 'ml/L' ELSE 'ml/L' END As data, CASE WHEN Unit='g/L' THEN (data4* 0.01129) ELSE data4 END As data4 FROM something where Type ='DATA' and ID='" + Session["name"].ToString() + "' Order By CONVERT(DateTime, CaptureTime,101) DESC asp.net sql divide-by-zero share|improve this question edited Oct 30 '12 at 9:57 Cyril Gandon 11.2k64088 asked Oct 30 '12 at 9:50 April 40115 possible duplicate of How to avoid the "divide by zero" error in SQL? –Leigh Dec 9 '12 at 6:03 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted The error is almost certainly coming from the second line here: CASE WHEN Unit='g/L' THEN nullif(data1* 0.02586,0) / nullif(data2* 0.02586,0) " + "ELSE (data1/data2)" + "END As Ratio," If the unit is not G/L and data2 is 0 you will get an error. Change it to: CASE WHEN Unit='g/
SQL Server 2014 Express resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Ask a question Quick access Forums home Browse forums users FAQ Search related threads Remove From My Forums Asked by: Divide by Zero Error [this.Adapter.Fill(dataTable);] Data Platform Development > ADO.NET Managed Providers Question 0 Sign in to vote I am getting a "Divide by http://stackoverflow.com/questions/13136406/divide-by-zero-error-encountered Zero Error Encountered" when I run my ASP.NET application. The error looks like is encountered when filling DataSet.I have a GridView on frontpage that is configured to get data from a Dataset which uses Stored Procedure to get data. The SP runs perfectly when I run in SQL Server but I don't know why is it throwing an error when I run from ASP.NET. Any https://social.msdn.microsoft.com/Forums/en-US/a17747d3-f9fd-4360-8120-5ca7280f0f4a/divide-by-zero-error-thisadapterfilldatatable?forum=adodotnetdataproviders help is really appreciated. I am attaching some images below to give more information: Image of Default.aspx page and DataSet Image of Error Image of Stored Procedure Code Image of Output when Stored Procedure is executed in SQL Server(I have noticed that when stored procedure is executed in SQL server, it returns a Value '0' in a second table. I am don't know why is "DECLARE @return_value int" and "SELECT 'Return Value' = @return_value" are created in the Stored Procedure when I created SP. Monday, October 30, 2006 8:15 PM Reply | Quote All replies 0 Sign in to vote The error appears due to division operations you are performed in stored procedure. Try to replace sum (x) / sum (y) with IIF (sum(y) = 0, valueInCaseOfSumIsZero, sum(x)/sum(y)). Wednesday, November 01, 2006 11:39 PM Reply | Quote Microsoft is conducting an online survey to understand your opinion of the Msdn Web site. If you choose to participate, the online survey will be presented to you when you leave the Msdn Web site.Would you like to participate? Privacy statement Help us improve MSDN. Visit our UserVoice Page t
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your http://www.codeproject.com/Questions/1009292/Divide-by-zero-error-encountered Blog quick answersQ&A Ask a Question View Unanswered Questions View All http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=86596 Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed divide by C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library divide by zero CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ Divide by zero error encountered Rate this: Please Sign up or sign in to vote. See more: ASP.NET SQL C#3.5 C#5 , + below attached code is not working , its showing one error message "Msg 8134, Level 16, State 1, Line 2 Divide by zero error encountered." "listedprice" and "closingprice' some fields are Zero is it possible to apply any condition . select *, round(((OverListedPrice/listedprice)-1)*100,3) as overlistedpercentage, Round(((NetGainorLoss/closingprice)-1*100),3) as netgainpercentage from (select c.BranchName as brname,c.BranchCode as brcode,c.listedprice as listedprice,c.ClosingPrice as closingprice,d.CurrentPrice, cast(d.CurrentPrice as decimal)-cast(c.ListedPrice as decimal) as OverListedPrice, cast(d.CurrentPrice as decimal)-cast(c.ClosingPrice as decimal) as NetGainorLoss from(select
SQL Server experts to answer whatever question you can come up with. Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums. SQL Server Forums Profile | ActiveTopics | Members | Search | ForumFAQ Register Now and get your question answered! Username: Password: Save Password Forgot your Password? All Forums SQL Server 2005 Forums Transact-SQL (2005) debugging "Divide by zero error encountered" Reply to Topic Printer Friendly Author Topic mike123 Flowing Fount of Yak Knowledge 1462 Posts Posted-07/19/2007: 09:48:03 Hi,I have a query that I'm getting this error on. I'm wondering if there are any simple tricks to debugging SPROCS when this occurs?I'm having problems figuring out exactly where the error is occuring, and also would like to know the best way to prevent this.Thanks very much!mike123 sshelper Posting Yak Master 216 Posts Posted-07/19/2007: 09:58:56 There are 3 ways of avoiding the Divide by zero error and you can refer to the following link for these:http://www.sql-server-helper.com/error-messages/msg-8134.aspxhttp://www.sql-server-helper.com/faq/select-p01.aspx (Question #10).SQL Server Helperhttp://www.sql-server-helper.com mike123 Flowing Fount of Yak Knowledge 1462 Posts Posted-07/19/2007: 10:34:55 thanks a bunch! I still couldnt find the divide by zero error somehow, for now I have successfully used SET ARITHABORT OFFSET ANSI_WARNINGS OFFAre there any downsides to using this ? Performance hits?Thanks again,Mike123 Topic Reply to Topic Printer Friendly Jump To: Select Forum General SQL Server Forums New to SQL Server Programming New to SQL Server Administration Script Library Data Corruption Issues Database Design and Application Architecture SQL Server 2012 Forums Transact-SQL (2012) SQL Server Administration (2012) SSIS and Import/Export (2012) Analysis Server and Reporting Services (2012) Replication (2012) Availability Groups and DR (2012) Other SQL Server 2012 Topics SQL Server 2008 Forums Transact-SQL (2008) SQL Server Administration (2008) SSIS and Import/Export (2008) High Availability (2008) Replication (2008) Analysis Server and Reporting Services (2008) Other SQL Server 2008 Topics SQL Server 2005 Forums Transact-SQL (2005) SQL