将日期行转换为sql

时间:2016-04-06 12:33:07

标签: mysql sql

我有一张包含以下数据的表格。我需要将日期行转换为列,并需要在相应日期填充合同计数。请帮忙到达代码。 这是表XXX中的数据 enter image description here

预期输出

enter image description here

请做到需要

这是我尝试过的代码。但是数据类型出错了。

    DECLARE @Proposed_Delv_Dt AS datetime
SELECT @Proposed_Delv_Dt = 
    COALESCE(@Proposed_Delv_Dt + ', ', '') +  CAST(@Proposed_Delv_Dt AS datetime)
    FROM ( select distinct Proposed_Delv_Dt from (select  PM.Project_Alias_name as 'Project Name', CD.Key_column_values as contractNumber, PLM.Type_of_picklist as Lease_type, 
PLM.Pick_List_description as TypeOfWork, PWS.Workflow_status_description as Contract_status,
  UM.Employee_id, SM.SBU_Name, UM.fULL_NAME as Assigned_To, UMAB.Full_Name as 
assigned_By, RM.Role_Description as role, CUD.Change_date as AssignedDate, CD.Proposed_delivery_date as 'Proposed_Delv_Dt'
from Contract_user_details CUD
left join Contract_Details CD on CD.Pkey = CUD.Fkey_Contract_Key
left join Project_Master PM on CD.Fkey_Project_Key = PM.Pkey
left join SBU_Master SM on SM.Pkey = PM.Fkey_Sbu_key
left join Pick_list_master PLM on CD.Fkey_Lease_Type = PLM.Pkey
left join Project_Workflow_Status PWS on CD.Fkey_Current_Workflow_Status = PWS.Pkey
left join Users_Master UM on CUD.Fkey_User_key = UM.Pkey
left join Users_Master UMAB on CUD.Fkey_assigned_by = UMAB.Pkey
left join Role_master RM on RM.pkey = CUD.Fkey_Role_key)f )d
SELECT @Proposed_Delv_Dt Dates

我希望o / p的日期用','(逗号)

分隔

0 个答案:

没有答案