Fred Webb
asked on
Pivot Rows to Columns
I have a table the holds 2 values for each item, the Max and Min values along with the flag for those values. I need the Values and the levels to be on the same row so that I only have 1 item number with those values, I was thinking of using Pivot but not sure how to do it dynamically as there are 760 rows. Any help would be greatly appreciated.
SELECT
[ITEMNMBR] = EXT00103.PT_UD_Key ,[VALUE ] = EXT00103.TOTAL,[LEVELS] = EXT00103.PT_UD_Number
FROM EXT00103
ASKER
Thanks for the quick response Low, but I am getting the following errors
Msg 207, Level 16, State 1, Line 3
Invalid column name 'value'.
Msg 207, Level 16, State 1, Line 3
Invalid column name 'levels'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'levels'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'levels'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'itemnmbr'.
Msg 207, Level 16, State 1, Line 3
Invalid column name 'value'.
Msg 207, Level 16, State 1, Line 3
Invalid column name 'levels'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'levels'.
Msg 207, Level 16, State 1, Line 4
Invalid column name 'levels'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'itemnmbr'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, Thank you
select itemnmbr,[1] as max,[2] as min
from ext00103 as a
pivot (max(value) for levels in ([1],[2])) as pvt
where levels in ('1','2')
order by 1