具有日期值的列的SQL Pivot

时间:2014-04-18 11:06:22

标签: sql

我有以下需要转动的数据表。

ContractDateName                    PlannedContractDateValue    ProjectID

1ST DESPATCH                       2006-06-29 00:00:00.000      4517
1ST DESPATCH                       2006-06-29 00:00:00.000      4518
1ST DESPATCH                       2007-07-17 00:00:00.000      3309
COMMON PART PACKING & SHIPMENT  2014-08-25 00:00:00.000     9120
COMMON PART PACKING & SHIPMENT  2014-10-17 00:00:00.000     7998
DESPATCH - COMMON PART              2014-03-14 00:00:00.000     9599
DESPATCH - COMMON PART              2014-04-14 00:00:00.000     7977
DESPATCH - COMMON PART              2014-05-09 00:00:00.000     8508
DESPATCH - COMMON PART              2014-06-17 00:00:00.000     9603
DESPATCH - ELECTRICAL CAR PART      2012-11-08 00:00:00.000     8802
DESPATCH - ELECTRICAL CAR PART      2014-04-30 00:00:00.000     9121
DESPATCH - ELECTRICAL COMMON PART   2009-06-01 00:00:00.000     3448
DESPATCH - ELECTRICAL COMMON PART   2009-06-22 00:00:00.000     2568
DESPATCH - ELECTRICAL COMMON PART   2009-08-25 00:00:00.000     2569

1 个答案:

答案 0 :(得分:0)

    select * 
from 
(
  select ContractDateName , PlannedContractDateValue, ProjectID
  from rows
) a
pivot