Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:05:44+00:00 2026-06-13T01:05:44+00:00

I am working in MS WebMatrix using razor. The issue I am having is

  • 0

I am working in MS WebMatrix using razor.

The issue I am having is that if one of my queries resolves to an error (dividing by 0, for instance) the whole page fails. I want the query to output “0” for this.

Code:

var itot = db.QueryValue("SELECT SUM(SUBTOTAL) from dbo.DR_TRANS where TRANSDATE = 41195 and SUBTOTAL >0");

var ctot = db.QueryValue("SELECT SUM(SUBTOTAL) from dbo.DR_TRANS where TRANSDATE = 41195 and TRANSTYPE = 1 and SUBTOTAL <0");

var nett = itot + ctot;

So, if either itot or ctot renders Null or error because there is no entries for the selected date, how do I get it to treat error as “0” so the math still works? In this example, itot is total invoices raised today, ctot is total credits raised today.

If there are no invoices yet, or if there are no credits raised yet, my code throws an error and shuts the page down. I want it to display 0 if there’s none of either, and the value of itot if theres no ctot.

What am I doing wrong? it works fine the moment there’s some of each, but I want it to work before that, because there’s other code on the page for displaying other query results.

I’m very new to coding queries, so there will be a basic answer I have missed in my online searching!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:05:45+00:00Added an answer on June 13, 2026 at 1:05 am

    Wrapping the aggregate function with COALESCE should return 0 rather than NULL:

    SELECT COALESCE(SUM(SUBTOTAL), 0)
       FROM dbo.DR_TRANS
       WHERE TRANSDATE = 41195
         AND SUBTOTAL >0
    

    ie a function that returns the first parameter if it is not null, and the second parameter if the first is NULL. I don’t know what function to use with webmatrix, but COALESCE is pretty standard. In Oracle, you could use NVL. ISNULL is another such function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using WebMatrix to build a webpage that queries our accounting software and displays
Working sample using one Table SELECT t.* FROM ( SELECT TITLE.name, (TITLE.value-TITLE.msp) AS Lower,
I have an ASP.NET Razor website that is working properly when I test locally
I'm working on a simple web project for mobile in Microsoft Webmatrix 2.0. For
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with an undisclosed API, I found a function that can set the number
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working with H2 I get this error when I try to write a row
Working with a Lucene index, I have a standard document format that looks something
Working with box2d and cocos2d, I've calculated two vectors: one is the vector pointing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.