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

  • SEARCH
  • Home
  • 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 7768689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:58:42+00:00 2026-06-01T15:58:42+00:00

So basically I’m making a program in C# and I need to make a

  • 0

So basically I’m making a program in C# and I need to make a query to the database. In this query I need to sum up all the values of a given column granted 2 other columns match my requirements. Then I take the value and put it into an “int” type variable.

SELECT SUM(Column1) FROM table WHERE Column2="blahblah" AND Column3="Case1" ...
int the_sum = System.Convert.ToInt32(sql.ExecuteScalar());

Now the problems is, Column3 can only have 2 types of string values, here I will call them Case1 or Case2 and I need the SUM of Column1 ONLY when column3 contains the Case1 value. Everything’s cool, except that its possible that all the values in Column3 are Case2. That way, there will be no instances for summing up and an error appears in the second line where I want to put the sum in my “the_sum” int:

int the_sum = System.Convert.ToInt32(sql.ExecuteScalar());

How do I get by this? Am I doing it all wrong here?

  • 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-01T15:58:44+00:00Added an answer on June 1, 2026 at 3:58 pm

    Change the SUM(column1) to ISNULL(SUM(column1),0)

    This way you will get back zero when there are no values to add..

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

Sidebar

Related Questions

Basically, I would like to decode a given HTML document, and replace all special
Basically from a database I am getting data that is formatted like this nameofproject101
Basically I'm attempting to add rows to a table, I need to do this
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically, I've seen this used all to often: public event MyEventHandler MyEvent; private void
Basically I've been given an implementation of a CircularQueue, I need to implement a
Basically what I need to do is write a function that takes in a
Basically I'd be looking to implement a method like this. IQueryAble GetQuery<T>(Entities db) or
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically this function is meant to store the height value of the element that

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.