-4

I have a table with the following values

enter image description here

and I need the output values as below.

enter image description here

Please help to arrive the code

Ullas
  • 11,450
  • 4
  • 33
  • 50
  • 2
    Don't tag products not involved. Are you using MySQL or MS SQL Server? – jarlh Feb 09 '16 at 10:15
  • 1
    Does this help? http://stackoverflow.com/questions/15745042/efficiently-convert-rows-to-columns-in-sql-server – Tom-db Feb 09 '16 at 10:16

1 Answers1

0

It's not pretty, but this would work:

select *
from
(
select nams_contract_number, 1 as Sequence, 'Preqc' as DataType, act_preqc, est_preqc
from table
union all
select nams_contract_number, 2 as Sequence, 'abstractoin' as DataType, act_abstraction, est_abstraction
from table
union all
select nams_contract_number, 3 as Sequence, 'review' as DataType, act_review, est_review
from table
union all
select nams_contract_number, 4 as Sequence, 'postreview' as DataType, act_postreview, est_postreview
from table
) x
order by x.nams_contract_number, x.sequence
simon at rcl
  • 7,326
  • 1
  • 17
  • 24