-1

How can I turn these columns into rows?

columns to rows

This is the select statement

SELECT
  MFGNO,
  COMP,
  COMP2,
  LINER_CONFIG
FROM FG_STANDARD_BOMS

This is what I tried (recycled code I found)

SELECT
  MFGNO,
  COMP,
  COMP2,
  LINER_CONFIG
FROM (SELECT
  CYCLETM,
  MFGNO
FROM FG_STANDARD_BOMS) d
PIVOT
(
MAX(CYCLETM)
FOR MFGNO IN (MFGNO, COMP, COMP2, LINER_CONFIG)
) piv;

Msg 265, Level 16, State 1, Line 13 The column name "MFGNO" specified in the PIVOT operator conflicts with the existing column name in the PIVOT argument.

gotqn
  • 42,737
  • 46
  • 157
  • 243
  • Please never post [images](https://meta.stackoverflow.com/questions/285551) of data. – Stu Apr 06 '23 at 19:22
  • That would be an UNPIVOT. Add tag for RDBMS used. Review https://stackoverflow.com/questions/75944366/how-do-i-create-an-access-query-to-get-multiple-row-one-row-for-each-column-in/75944657#75944657 and https://stackoverflow.com/questions/32797912/how-to-unpivot-a-table-in-sql-server – June7 Apr 06 '23 at 23:04

1 Answers1

0

Try this:

SELECT MFGNO
      ,[column]
      ,[value]
FROM FG_STANDARD_BOMS
UNPIVOT
(
    [value] FROM [column] IN ([COMP], [COMP2], [LINER_CONFIG])
) UNVPT;
gotqn
  • 42,737
  • 46
  • 157
  • 243