Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.sqlserver.programming > #31352
| From | Erland Sommarskog <esquel@sommarskog.se> |
|---|---|
| Newsgroups | microsoft.public.sqlserver.programming |
| Subject | Re: Ordering the columns in a pivot table |
| Date | 2020-04-12 13:59 +0200 |
| Organization | Erland Sommarskog |
| Message-ID | <XnsAB9D8E450C905Yazorman@127.0.0.1> (permalink) |
| References | <9c212941-b3a2-4f07-b29c-e8145580bbad@googlegroups.com> |
SELECT PE.TestID,
MIN(CASE PU.PresentOrder WHEN 1 THEN PE.TextValue END) AS Param1,
MIN(CASE PU.PresentOrder WHEN 2 THEN PE.TextValue END) AS Param2,
MIN(CASE PU.PresentOrder WHEN 3 THEN PE.TextValue END) AS Param3,
MIN(CASE PU.PresentOrder WHEN 4 THEN PE.TextValue END) AS Param4,
MIN(CASE PU.PresentOrder WHEN 5 THEN PE.TextValue END) AS Param5
FROM ParametersEntries PE
JOIN ParametersUser PU ON PE.TestID = PU.TestID
GROUP BY PE.TestID
You may note that I don't use the PIVOT keyward. The above method with CASE
is a lot more flexible and easier to understand.
Back to microsoft.public.sqlserver.programming | Previous | Next — Previous in thread | Find similar
Ordering the columns in a pivot table John Hall <foundarecord@gmail.com> - 2020-04-11 09:00 -0700 Re: Ordering the columns in a pivot table Erland Sommarskog <esquel@sommarskog.se> - 2020-04-12 13:59 +0200
csiph-web