I'd need to get a single table with (potentially several) columns receiving their values from a details table. The details table basically has these columns:
DetailID,
MasterID (foreign key to master ID),
DetailName (nvarchar()),
DetailValue (nvarchar())
So far I succeeded by using:
SELECT Master.ID,
(SELECT DetailValue FROM Detail WHERE Master.ID=Detail.MasterID AND DetailName='Name1') as Detail1,
(SELECT DetailValue FROM Detail WHERE Master.ID=Detail.MasterID AND DetailName='Name2') as Detail2
FROM Master
but this scales very badly when I add more details.
What would be an efficient way to do this?