Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Change the data from vertical to horizontal

Author  Topic 

wewe_2090
Starting Member

4 Posts

Posted - 2014-04-04 : 08:33:31
Hi,

i would like to write a SQL query from database table_A (original from database) to display in table B.

original from database, table_A


i want to write the SQL query to display it like below:


please help.

thank you

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2014-04-05 : 00:51:06
SELECT DISTINCT Gid
, Name
, CASE WHEN MAX(Pic) = 'Group Leader(Checker)'
THEN 'Group Leader(Checker)' END AS Pic1,
CASE WHEN MIN(Pic) = 'Design Manager(Approver)'
THEN 'Design Manager(Approver)' END AS Pic2
FROM @Table
GROUP BY GID,Name
ORDER BY Gid

Veera
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-04-05 : 04:21:02
do you have max 2 pic for each GID & NAME ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

wewe_2090
Starting Member

4 Posts

Posted - 2014-04-06 : 23:20:04
quote:
Originally posted by VeeranjaneyuluAnnapureddy

SELECT DISTINCT Gid
, Name
, CASE WHEN MAX(Pic) = 'Group Leader(Checker)'
THEN 'Group Leader(Checker)' END AS Pic1,
CASE WHEN MIN(Pic) = 'Design Manager(Approver)'
THEN 'Design Manager(Approver)' END AS Pic2
FROM @Table
GROUP BY GID,Name
ORDER BY Gid

Veera



thank you. it is solved.
Go to Top of Page
   

- Advertisement -