Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.sqlserver.programming > #31351

How do I order the columns on a pivot table?

Newsgroups microsoft.public.sqlserver.programming
Date 2020-04-11 09:08 -0700
Message-ID <32b39068-acc8-48ef-ac56-7f80bc2ee65b@googlegroups.com> (permalink)
Subject How do I order the columns on a pivot table?
From John Hall <foundarecord@gmail.com>

Show all headers | View raw


I have a data table with these 3 columns
SELECT [TestID],[ParameterID],[TextValue]  FROM [ParameterEntries]
And a setup table with these 3 columns
SELECT [PartID], [ParameterID], [PresentOrder]  FROM [ParametersUsed]

SELECT TestID, [1] as Param1, [2] as Param2, [3] as Param3, [4] as Param4, [5] as Param5
FROM (select TestID, TextValue,
    row_number() over(partition by TestID ORDER BY ParameterID) rnk
  FROM ParameterEntries WHERE TestID = (SELECT TOP 1 TestID FROM Subgroups WHERE CharID = 502107)
) p
pivot(max(TextValue) for rnk in ([1], [2], [3], [4], [5])) piv

TestID  Param1          Param2  Param3  Param4  Param5
506789  20147338        3w        2.14  1.49    1.73

SELECT [PartID], [ParameterID], [PresentOrder]
  FROM [ParametersUsed]
  WHERE PartID = (SELECT PartID FROM CharList WHERE CharID = 502107)
  ORDER BY PresentOrder

PartID  ParameterID  PresentOrder
502014        154             1
502014        502009          2
502014        502022          3
502014        502023          4
502014        502024          5

How do I put the Param1, Param2, Param3... in PresentOrder?

Back to microsoft.public.sqlserver.programming | Previous | NextNext in thread | Find similar


Thread

How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-11 09:08 -0700
  Re: How do I order the columns on a pivot table? Erland Sommarskog <esquel@sommarskog.se> - 2020-04-12 13:59 +0200
    Re: How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-12 12:02 -0700
      Re: How do I order the columns on a pivot table? Erland Sommarskog <esquel@sommarskog.se> - 2020-04-12 21:32 +0200
      Re: How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-15 12:54 -0700
        Re: How do I order the columns on a pivot table? Erland Sommarskog <esquel@sommarskog.se> - 2020-04-16 20:02 +0200
    Re: How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-12 12:27 -0700
    Re: How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-12 12:43 -0700
      Re: How do I order the columns on a pivot table? Erland Sommarskog <esquel@sommarskog.se> - 2020-04-12 22:31 +0200
        Re: How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-12 14:10 -0700
          Re: How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-12 14:14 -0700
          Re: How do I order the columns on a pivot table? Erland Sommarskog <esquel@sommarskog.se> - 2020-04-12 23:15 +0200
        Re: How do I order the columns on a pivot table? John Hall <foundarecord@gmail.com> - 2020-04-12 14:18 -0700
          Re: How do I order the columns on a pivot table? Erland Sommarskog <esquel@sommarskog.se> - 2020-04-12 23:41 +0200

csiph-web