Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL - Join Statment with SUM

Posted on 2013-02-04
4
Medium Priority
?
369 Views
Last Modified: 2013-02-04
I've attached a pic of an excel spreadsheet with a table definition.  I've been trying to write a SQL statement what will perform a SUM on TableF.Amount where TableG_ID <> 2.

However my sum gives me a result of 25 (adding the 10 + 15 together).  

I tried to make the tables similar to what I am working with.  Table G will have many rows of data and I need result to sum but exclude where TableG_ID = 2.

Thanks
Tables.png
0
Comment
Question by:CipherIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 38852764
write your sum like this:  


sum (
    case when  TableG_ID <> 2 then TableF.Amount else 0 end
   ) as TableAMountFexcludingG2
0
 
LVL 1

Author Comment

by:CipherIS
ID: 38852817
That got me closer but now I'm somehow getting a total of 30.  Seems that it is adding 15 twice.  But when I run a select statement it shows as

0
0
15

but in sum I get 30.

Any ideas?
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 38852885
can you post your query?
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 38852963
Thanks
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

670 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