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 4626622
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:26:51+00:00 2026-05-22T03:26:51+00:00

I would like to form an SQL query to achieve the following: I have

  • 0

I would like to form an SQL query to achieve the following:

I have a table with columns A and B amongst others. I would like to obtain the sum for A and the sum for B (according to the WHERE clause I state), along with various other values. However, it is possible for B to contain null values. I would also like, returned via the same query, the value of the sum of A’s for which the corresponding B value is not null. This is the only value returned which I want to be effected by whether or not B is null.

So, any suggestions on how I can achieve this? I am working in SQL Server 2008.

Any help is much appreciated

  • 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-05-22T03:26:51+00:00Added an answer on May 22, 2026 at 3:26 am
    SELECT SUM(A) AS SumA, 
           SUM(B) AS SumB, 
           SUM(CASE WHEN B IS NOT NULL THEN A END) As Foo, /*... Rest of Query*/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to form a query where an associated collection has been restricted,
I would like to have Ajax form in Rails so i'm using form_remote_tag. The
I would like to have a form that can submit to two different action
Stackoverflowers, I have a resultset from a SQL query in the form of: Category
I have a datagridview in a windows form based on the following query :
According to MSDN , [The pipe name] must have the following form: \\.\pipe\pipename The
I would like to create a sql query that returns results together for 2
I have a SQL query of the form SELECT ... FROM A@DB1 a, B@DB1
I would like to take my result from a SQL query, which I got
We have a simple access database, and would like a button on a form

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.