How to include different total same row in SQL script

We have a table that with 3 columns: DocContract, Provider and Amount.

The there different types of Provider.

Sample of data:
DocContract   Provider	AMOUNT
Contract1     IBM       3.1
Contract1     TWA       15
Contract1     TWA       2.25
Contract2     IBM       1.1
Contract2     IBM       3.6
Contract2     IBM       1.1
Contract2     TWA       1.1
Contract2     TWA       1.1

Open in new window


We want the display to be:
Contract    IBM  TWA
Contract1   3.1  17.25
Contract2   5.8  2.2

Open in new window



So far this is what we have:
SELECT DocContract, (select sum(Amount) FROM @Sales s1 WHERE s1.Provider='TWA') 'TWA',
      (select sum(s2.Amount) FROM @Sales s2 WHERE s2.Provider='IBM' AND s2.Provider=s1.Provider) 'IBM'
      FROM @Sales
      GROUP BY DocContract

Open in new window


Please advice.
rayluvsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rayluvsAuthor Commented:
Here is a sample data:
DECLARE @Sales TABLE(
        DocContract VARCHAR(20),
        Provider VARCHAR(20),
        AMOUNT FLOAT
)
INSERT INTO @Sales SELECT 'Contract1','TWA', 2.25 
INSERT INTO @Sales SELECT 'Contract1','IBM', 3.1 
INSERT INTO @Sales SELECT 'Contract1','TWA', 15 
INSERT INTO @Sales SELECT 'Contract2','IBM', 3.6 
INSERT INTO @Sales SELECT 'Contract2','IBM', 1.1 
INSERT INTO @Sales SELECT 'Contract2','TWA', 1.1 
INSERT INTO @Sales SELECT 'Contract2','TWA', 1.1 
INSERT INTO @Sales SELECT 'Contract2','IBM', 1.1 

select * from @sales 
ORDER BY 1,2

Open in new window

0
PortletPaulfreelancerCommented:
try this:

SELECT
        DocContract
      , SUM(case when Provider = 'TWA' then Amount end ) as 'TWA'
      , SUM(case when Provider = 'IBM' then Amount end ) as 'IBM'
FROM @Sales
GROUP BY DocContract

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rayluvsAuthor Commented:
Thanx Worked! (how can we have missed it)!
0
rayluvsAuthor Commented:
Thanx
0
PortletPaulfreelancerCommented:
no problem, thank you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.