Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.sqlserver.programming > #31352
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Erland Sommarskog <esquel@sommarskog.se> |
| Newsgroups | microsoft.public.sqlserver.programming |
| Subject | Re: Ordering the columns in a pivot table |
| Date | Sun, 12 Apr 2020 13:59:08 +0200 |
| Organization | Erland Sommarskog |
| Lines | 12 |
| Message-ID | <XnsAB9D8E450C905Yazorman@127.0.0.1> (permalink) |
| References | <9c212941-b3a2-4f07-b29c-e8145580bbad@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | reader02.eternal-september.org; posting-host="ff96d794c89c0239ea5bf45a2c7528e6"; logging-data="28044"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+t+bD2AqCVwy4w/kS4cmKS" |
| User-Agent | Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32) |
| Cancel-Lock | sha1:Ei8oxkCAH0tKRgEmnQlL5/Ec4mo= |
| Xref | csiph.com microsoft.public.sqlserver.programming:31352 |
Show key headers only | View raw
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