SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 pivot
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

415 Posts

Posted - 06/13/2013 :  05:31:13  Show Profile  Reply with Quote
i have a data as below:

ID Name Amount Country Payment
10 Mary 123.45 US NULL
10 Mary 999.99 AU 70
10 John 123.45 US NULL
10 John 999.99 AU 70
10 Zack 123.45 US NULL
10 Zack 999.99 AU 70

how can i output as below:

ID Name Amount Country Payment
10 Mary 123.45 AU 70
10 John 123.45 AU 70
10 Zack 123.45 AU 70

use pivot?

bandi
Flowing Fount of Yak Knowledge

India
2224 Posts

Posted - 06/13/2013 :  05:35:35  Show Profile  Reply with Quote
SELECT *
FROM Table
WHERE Payment IS NOT NULL

--Is there any logic behind that output?
why PIVOT? for that above output pivot is not required
--
Chandu

Edited by - bandi on 06/13/2013 05:36:32
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/13/2013 :  05:36:46  Show Profile  Reply with Quote

SELECT ID,Name,
MAX(CASE WHEN Country='US' THEN Amount END) AS Amount,
MAX(CASE WHEN Country='AU' THEN Country END) AS Country,
MAX(Payment) AS Payment
FROM Table
GROUP BY ID,Name


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/13/2013 :  05:37:47  Show Profile  Reply with Quote
I cant understand the significance of the output though. whats the purpose of merging US Amount to AU?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000