Solved

SQL Link SQL Statement to table to get a name

Posted on 2014-09-15
4
157 Views
Last Modified: 2014-09-16
Hi
How do I alter the following SQL so that it links to a table called Customers to get [Customer Name]
(The Table Customers has CustomerID,[Customer Name]....)

select
 CustomerID, sum(amount) amount
 from
  (
    select [Link ID] CustomerID, Amount * -1 As Amount from payments
    union all
    select customerId, [inv amt] from invoices
 ) SubQuery
 group by CustomerID
0
Comment
Question by:Murray Brown
[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 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40323896
select
  SubQuery.CustomerID, c.[Customer Name], sum(SubQuery.amount) amount
  from
   (
     select [Link ID] CustomerID, Amount * -1 As Amount from payments
     union all
     select customerId, [inv amt] from invoices
  ) SubQuery
inner join customers c on
    c.CustomerID = SubQuery.CustomerID
group by SubQuery.CustomerID
0
 

Author Closing Comment

by:Murray Brown
ID: 40323991
Thanks very much
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 40324098
You're welcome.

D'OH, I didn't add the name to the GROUP BY (just to be clear to anyone else looking at this):

group by SubQuery.CustomerID, c.[Customer Name]
0
 

Author Comment

by:Murray Brown
ID: 40325153
Thanks. Picked that up. appreciate the help
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

627 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