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 2005 Forums
 Transact-SQL (2005)
 SQL Question

Author  Topic 

chandra_ags
Starting Member

1 Post

Posted - 2009-09-09 : 01:41:24
I have 2 tables shown as below:

SID | Personnel | Remarks |
1 me good
2 he bad
3 she average


PID | SID | Attribute | Rate |
1 1 1 4
2 1 2 3
3 1 3 4
4 1 4 3


And I want to generate this result
Result:

Personnel | Attribute1 | Attribute2| Attribute3 | Attribute4 | Remarks
me 4(Rate) 3(Rate) 4(Rate) 3(Rate) good


is this possible? need help....thanks in advance...


Chan Chan

Sachin.Nand

2937 Posts

Posted - 2009-09-09 : 02:34:53
Are the rate ids going to be static?

PBUH
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-09-09 : 03:00:02
Hi,

SELECT t.personnel,max([1]) AS Attribute1 ,max([2]) AS Attribute2, max([3]) AS Attribute3, max([4]) AS 'Attribute4',
t.remarks
FROM @TEMP t
inner join @TEMP1 t1 as t.sid = t1.sid
PIVOT ( MAX(Rate) for Attribute in ( [1],[2],[3],[4]))p
GROUP BY t.personnel,t.remarks
Go to Top of Page
   

- Advertisement -