MS SQL Pivot Another Table Multiple Times
问题 I have a database with the following structure ID Name 1 John 2 Doe 3 Dave 4 Smith Another table holds employee relatives ID EmpID RelativeType Name 1 1 Son x 2 1 Daughter y 3 1 Wife a 4 1 Friend b 5 1 Father c 6 1 Friend e Childs can be fixed upto maximum of 8 and friends can be maximum of 3 I was able to make a pivot query below to bring childs, but unable to pivot again to fetch 3 friends, father etc. This is my query: select * from ( select e.ID, e.FirstName, CASE WHEN es.RelativeType =