I have a table "contacts" with
EMPid ContactID EmergencyYN Priority
---------------------------------------
10 20 Y 1
10 39 N 1
10 45 Y 2
11 21 N 2
12 20 Y 2
12 25 Y 1
12 33 Y 3
What I would like is as a result set is
EmpID EmergencyContact1 EmergencyContact2 EmergencyContact3
------------------------------------------------------------------
10 20 45
11
12 25 20 33
psuedo sql is as close as I can get:
So n = max number of contacts where EmergencyYN =Y per empID
Then build a string for x = 1 to N
@sql = @sql + 'EmergencyContact'+x
next
Can some guru help me to do this?