尽量避免在SQL Server查询中使用UNION

时间:2017-08-03 17:34:59

标签: sql sql-server union

我有一个查询,为呼叫中心收集不同的指标:

    SELECT      CONCAT (DEPARTMENT_DESC, 'Week', datepart(wk, ROW_DATE)) As Dept_Date,
            datepart(wk, ROW_DATE) as weeknum,
            DEPARTMENT_DESC AS DEPT,
            SUM([CALLS_OFFERED_ACTUALS]) As LCW_Calls_Offered,
            MAX(LCW) AS LCW,
            (SUM(ANSTIME) / SUM(CALLS_ANSWERED_ACTUALS)) AS ASA,
            SUM(HANDLED_TIME) / SUM(CALLS_ANSWERED_ACTUALS) AS AHT,
            SUM(HANDLED_TIME) as handletime,
            SUM(CALLS_OFFERED_FCST) AS Call_Target,
            SUM(CALLS_ANSWERED_ACTUALS) as call_answered,
            CAST(1.000*(SUM(TRANSFERS)+SUM(CONFERENCE)) / SUM(CALLS_ANSWERED_ACTUALS) AS DECIMAL(19,3)) AS Transf_Rate,
            CAST(1.000*(SUM(CALLS_ABD_ACTUALS)) / SUM([CALLS_OFFERED_ACTUALS]) AS DECIMAL(19,3)) AS Abandon_Rate,
            1-CAST(1.000*(SUM(LCW60)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT,
            CAST(1.000*(SUM(ONLINETIME)-SUM(AVAILTIME)-SUM(ALARMTIME))/SUM(ONLINETIME)  AS DECIMAL(19,3)) AS Occupancy,
            CAST(1.000*(SUM(PRODTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Productivity,
            CAST(1.000*(SUM(AVAILTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Availab,
            CAST(1.000*(SUM(OVERTIME)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Overtime,
            CAST(1.000*(SUM(UNPROD_TIME_UNPLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Unplanned_Shrink,
            CAST(1.000*(SUM(UNPROD_TIME_PLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Planned_Shrink,
            CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS SL_Within_20,
            CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)+SUM(CALLS_ANSWERED_INT3)+SUM(CALLS_ANSWERED_INT4)+SUM(CALLS_ANSWERED_INT5)+SUM(CALLS_ANSWERED_INT6)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS Calls_Within_60,
            1-CAST(1.000*(SUM(LCW300)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT1,
            1-CAST(1.000*(SUM(LCW120)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT2
      FROM [GEMDB].[dbo].[v_calls_LCW_Splitday]
  where datepart(wk, ROW_DATE) >= (datepart(wk, GETDATE()) - 6) AND datepart(year, ROW_DATE) = 2017
  GROUP BY datepart(wk, ROW_DATE), DEPARTMENT_DESC --((CALLS_ANSWERED_INT1 + CALLS_ANSWERED_INT2) / [CALLS_OFFERED_ACTUALS]) 
  ORDER BY datepart(wk, ROW_DATE

结果按周数和数字分组。部门(计费,技术支持,保留等)

我们决定创建一个名为客户服务的新子部门,该部门由Billing& amp;技术支持。

我找到了一种方法,通过对另一个只选择Billing&数据的数据的UNION执行UNION。技术支持。

这样运行正常,但查询从花费20秒到超过3分钟完成:

/****** Script for SelectTopNRows command from SSMS  ******/


SELECT      CONCAT ('CS', 'Week', datepart(wk, ROW_DATE)) As Dept_Date,
            datepart(wk, ROW_DATE) as weeknum,
            CONCAT('CS','DEPT') AS DEPT,
            SUM([CALLS_OFFERED_ACTUALS]) As LCW_Calls_Offered,
            MAX(LCW) AS LCW,
            (SUM(ANSTIME) / SUM(CALLS_ANSWERED_ACTUALS)) AS ASA,
            SUM(HANDLED_TIME) / SUM(CALLS_ANSWERED_ACTUALS) AS AHT,
            SUM(HANDLED_TIME) as handletime,
            SUM(CALLS_OFFERED_FCST) AS Call_Target,
            SUM(CALLS_ANSWERED_ACTUALS) as call_answered,
            CAST(1.000*(SUM(TRANSFERS)+SUM(CONFERENCE)) / SUM(CALLS_ANSWERED_ACTUALS) AS DECIMAL(19,3)) AS Transf_Rate,
            CAST(1.000*(SUM(CALLS_ABD_ACTUALS)) / SUM([CALLS_OFFERED_ACTUALS]) AS DECIMAL(19,3)) AS Abandon_Rate,
            1-CAST(1.000*(SUM(LCW60)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT,
            CAST(1.000*(SUM(ONLINETIME)-SUM(AVAILTIME)-SUM(ALARMTIME))/SUM(ONLINETIME)  AS DECIMAL(19,3)) AS Occupancy,
            CAST(1.000*(SUM(PRODTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Productivity,
            CAST(1.000*(SUM(AVAILTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Availab,
            CAST(1.000*(SUM(OVERTIME)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Overtime,
            CAST(1.000*(SUM(UNPROD_TIME_UNPLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Unplanned_Shrink,
            CAST(1.000*(SUM(UNPROD_TIME_PLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Planned_Shrink,
            CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS SL_Within_20,
            CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)+SUM(CALLS_ANSWERED_INT3)+SUM(CALLS_ANSWERED_INT4)+SUM(CALLS_ANSWERED_INT5)+SUM(CALLS_ANSWERED_INT6)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS Calls_Within_60,
            1-CAST(1.000*(SUM(LCW300)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT1,
            1-CAST(1.000*(SUM(LCW120)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT2
        INTO #TEMP_CS   
    FROM [GEMDB].[dbo].[v_calls_LCW_Splitday]
  where datepart(wk, ROW_DATE) >= (datepart(wk, GETDATE()) - 6) AND datepart(year, ROW_DATE) = 2017
  AND DEPARTMENT_DESC IN ('BILLING', 'TechOps')
   GROUP BY datepart(wk, ROW_DATE) --((CALLS_ANSWERED_INT1 + CALLS_ANSWERED_INT2) / [CALLS_OFFERED_ACTUALS]) 
  ORDER BY datepart(wk, ROW_DATE)


  SELECT        CONCAT (DEPARTMENT_DESC, 'Week', datepart(wk, ROW_DATE)) As Dept_Date,
            datepart(wk, ROW_DATE) as weeknum,
            DEPARTMENT_DESC AS DEPT,
            SUM([CALLS_OFFERED_ACTUALS]) As LCW_Calls_Offered,
            MAX(LCW) AS LCW,
            (SUM(ANSTIME) / SUM(CALLS_ANSWERED_ACTUALS)) AS ASA,
            SUM(HANDLED_TIME) / SUM(CALLS_ANSWERED_ACTUALS) AS AHT,
            SUM(HANDLED_TIME) as handletime,
            SUM(CALLS_OFFERED_FCST) AS Call_Target,
            SUM(CALLS_ANSWERED_ACTUALS) as call_answered,
            CAST(1.000*(SUM(TRANSFERS)+SUM(CONFERENCE)) / SUM(CALLS_ANSWERED_ACTUALS) AS DECIMAL(19,3)) AS Transf_Rate,
            CAST(1.000*(SUM(CALLS_ABD_ACTUALS)) / SUM([CALLS_OFFERED_ACTUALS]) AS DECIMAL(19,3)) AS Abandon_Rate,
            1-CAST(1.000*(SUM(LCW60)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT,
            CAST(1.000*(SUM(ONLINETIME)-SUM(AVAILTIME)-SUM(ALARMTIME))/SUM(ONLINETIME)  AS DECIMAL(19,3)) AS Occupancy,
            CAST(1.000*(SUM(PRODTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Productivity,
            CAST(1.000*(SUM(AVAILTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Availab,
            CAST(1.000*(SUM(OVERTIME)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Overtime,
            CAST(1.000*(SUM(UNPROD_TIME_UNPLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Unplanned_Shrink,
            CAST(1.000*(SUM(UNPROD_TIME_PLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Planned_Shrink,
            CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS SL_Within_20,
            CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)+SUM(CALLS_ANSWERED_INT3)+SUM(CALLS_ANSWERED_INT4)+SUM(CALLS_ANSWERED_INT5)+SUM(CALLS_ANSWERED_INT6)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS Calls_Within_60,
            1-CAST(1.000*(SUM(LCW300)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT1,
            1-CAST(1.000*(SUM(LCW120)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT2
            INTO #TEMP_ALL
   FROM [GEMDB].[dbo].[v_calls_LCW_Splitday]
  where datepart(wk, ROW_DATE) >= (datepart(wk, GETDATE()) - 6) AND datepart(year, ROW_DATE) = 2017
   GROUP BY datepart(wk, ROW_DATE), DEPARTMENT_DESC --((CALLS_ANSWERED_INT1 + CALLS_ANSWERED_INT2) / [CALLS_OFFERED_ACTUALS]) 
     ORDER BY datepart(wk, ROW_DATE)


  SELECT *
  FROM #TEMP_ALL
  UNION
  SELECT *
  FROM #TEMP_CS

  DROP TABLE #TEMP_ALL
  DROP TABLE #TEMP_CS

有没有更有效的方法来实现这一目标?我们无法等待3分钟+以完成此查询。

谢谢!

1 个答案:

答案 0 :(得分:2)

  • 不确定为什么你需要临时表
  • 不确定为什么需要使用union vs union all
  • 为避免结合,为什么不使用案例陈述:case when DEPARTMENT_DESC in IN ('BILLING', 'TechOps') then 'Customer Service' else DEPARTMENT_DESC end

保持联合但使用union all并避开临时表。

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT CONCAT ('CS', 'Week', datepart(wk, ROW_DATE)) As Dept_Date
     , datepart(wk, ROW_DATE) as weeknum
     , CONCAT('CS','DEPT') AS DEPT
     , SUM([CALLS_OFFERED_ACTUALS]) As LCW_Calls_Offered
     , MAX(LCW) AS LCW
     , SUM(ANSTIME) / SUM(CALLS_ANSWERED_ACTUALS) AS ASA
     , SUM(HANDLED_TIME) / SUM(CALLS_ANSWERED_ACTUALS) AS AHT
     , SUM(HANDLED_TIME) as handletime
     , SUM(CALLS_OFFERED_FCST) AS Call_Target
     , SUM(CALLS_ANSWERED_ACTUALS) as call_answered
     , CAST(1.000*(SUM(TRANSFERS)+SUM(CONFERENCE)) / SUM(CALLS_ANSWERED_ACTUALS) AS DECIMAL(19,3)) AS Transf_Rate
     , CAST(1.000*(SUM(CALLS_ABD_ACTUALS)) / SUM([CALLS_OFFERED_ACTUALS]) AS DECIMAL(19,3)) AS Abandon_Rate
     , 1-CAST(1.000*(SUM(LCW60)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT
     , CAST(1.000*(SUM(ONLINETIME)-SUM(AVAILTIME)-
     , SUM(ALARMTIME))/SUM(ONLINETIME)  AS DECIMAL(19,3)) AS Occupancy
     , CAST(1.000*(SUM(PRODTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Productivity
     , CAST(1.000*(SUM(AVAILTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Availab
     , CAST(1.000*(SUM(OVERTIME)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Overtime
     , CAST(1.000*(SUM(UNPROD_TIME_UNPLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Unplanned_Shrink
     , CAST(1.000*(SUM(UNPROD_TIME_PLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Planned_Shrink
     , CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS SL_Within_20
     , CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)+SUM(CALLS_ANSWERED_INT3)+SUM(CALLS_ANSWERED_INT4)+SUM(CALLS_ANSWERED_INT5)+SUM(CALLS_ANSWERED_INT6)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS Calls_Within_60
     , 1-CAST(1.000*(SUM(LCW300)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT1
     , 1-CAST(1.000*(SUM(LCW120)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT2
FROM [GEMDB].[dbo].[v_calls_LCW_Splitday]
WHERE  datepart(wk, ROW_DATE) >= (datepart(wk, GETDATE()) - 6) 
  AND datepart(year, ROW_DATE) = 2017
  AND DEPARTMENT_DESC IN ('BILLING', 'TechOps')
GROUP BY datepart(wk, ROW_DATE) --((CALLS_ANSWERED_INT1 + CALLS_ANSWERED_INT2) / [CALLS_OFFERED_ACTUALS]) 
ORDER BY datepart(wk, ROW_DATE)

UNION ALL

SELECT CONCAT (DEPARTMENT_DESC, 'Week', datepart(wk, ROW_DATE)) As Dept_Date
     , datepart(wk, ROW_DATE) as weeknum
     , DEPARTMENT_DESC AS DEPT
     , SUM([CALLS_OFFERED_ACTUALS]) As LCW_Calls_Offered
     , MAX(LCW) AS LCW
     , SUM(ANSTIME) / SUM(CALLS_ANSWERED_ACTUALS) AS ASA
     , SUM(HANDLED_TIME) / SUM(CALLS_ANSWERED_ACTUALS) AS AHT
     , SUM(HANDLED_TIME) as handletime
     , SUM(CALLS_OFFERED_FCST) AS Call_Target
     , SUM(CALLS_ANSWERED_ACTUALS) as call_answered
     , CAST(1.000*(SUM(TRANSFERS)+SUM(CONFERENCE)) / SUM(CALLS_ANSWERED_ACTUALS) AS DECIMAL(19,3)) AS Transf_Rate
     , CAST(1.000*(SUM(CALLS_ABD_ACTUALS)) / SUM([CALLS_OFFERED_ACTUALS]) AS DECIMAL(19,3)) AS Abandon_Rate
     , 1-CAST(1.000*(SUM(LCW60)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT
     , CAST(1.000*(SUM(ONLINETIME)-SUM(AVAILTIME)-SUM(ALARMTIME))/SUM(ONLINETIME)  AS DECIMAL(19,3)) AS Occupancy
     , CAST(1.000*(SUM(PRODTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Productivity
     , CAST(1.000*(SUM(AVAILTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Availab
     , CAST(1.000*(SUM(OVERTIME)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Overtime
     , CAST(1.000*(SUM(UNPROD_TIME_UNPLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Unplanned_Shrink
     , CAST(1.000*(SUM(UNPROD_TIME_PLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Planned_Shrink
     , CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS SL_Within_20
     , CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)+SUM(CALLS_ANSWERED_INT3)+SUM(CALLS_ANSWERED_INT4)+SUM(CALLS_ANSWERED_INT5)+SUM(CALLS_ANSWERED_INT6)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS Calls_Within_60
     , 1-CAST(1.000*(SUM(LCW300)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT1
     , 1-CAST(1.000*(SUM(LCW120)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT2

FROM [GEMDB].[dbo].[v_calls_LCW_Splitday]
WHERE datepart(wk, ROW_DATE) >= (datepart(wk, GETDATE()) - 6) 
  AND datepart(year, ROW_DATE) = 2017
GROUP BY datepart(wk, ROW_DATE)
       , DEPARTMENT_DESC --((CALLS_ANSWERED_INT1 + CALLS_ANSWERED_INT2) / [CALLS_OFFERED_ACTUALS]) 
ORDER BY datepart(wk, ROW_DATE)

现在没有工会,你只需要一个case语句用一个case

替换department_Desc
case when DEPARTMENT_DESC in IN ('BILLING', 'TechOps')  
                then 'Customer Service' 
                else DEPARTMENT_DESC end

所以我接受了你的第一个询问并做了那件事。

SELECT CONCAT(case when DEPARTMENT_DESC in IN ('BILLING', 'TechOps')  
                   then 'Customer Service' 
                   else DEPARTMENT_DESC end
              , 'Week', datepart(wk, ROW_DATE)) As Dept_Date
     , datepart(wk, ROW_DATE) as weeknum
     , case when DEPARTMENT_DESC in IN ('BILLING', 'TechOps')  
            then 'Customer Service' 
            else DEPARTMENT_DESC end AS DEPT
     , SUM([CALLS_OFFERED_ACTUALS]) As LCW_Calls_Offered
     , MAX(LCW) AS LCW
     , SUM(ANSTIME) / SUM(CALLS_ANSWERED_ACTUALS) AS ASA
     , SUM(HANDLED_TIME) / SUM(CALLS_ANSWERED_ACTUALS) AS AHT
     , SUM(HANDLED_TIME) as handletime
     , SUM(CALLS_OFFERED_FCST) AS Call_Target
     , SUM(CALLS_ANSWERED_ACTUALS) as call_answered
     , CAST(1.000*(SUM(TRANSFERS)+SUM(CONFERENCE)) / SUM(CALLS_ANSWERED_ACTUALS) AS DECIMAL(19,3)) AS Transf_Rate
     , CAST(1.000*(SUM(CALLS_ABD_ACTUALS)) / SUM([CALLS_OFFERED_ACTUALS]) AS DECIMAL(19,3)) AS Abandon_Rate
     , 1-CAST(1.000*(SUM(LCW60)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT
     , CAST(1.000*(SUM(ONLINETIME)-SUM(AVAILTIME)-SUM(ALARMTIME))/SUM(ONLINETIME)  AS DECIMAL(19,3)) AS Occupancy
     , CAST(1.000*(SUM(PRODTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Productivity
     , CAST(1.000*(SUM(AVAILTIME)) / SUM(ATWORKTIME) AS DECIMAL(19,3)) AS Availab
     , CAST(1.000*(SUM(OVERTIME)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Overtime
     , CAST(1.000*(SUM(UNPROD_TIME_UNPLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Unplanned_Shrink
     , CAST(1.000*(SUM(UNPROD_TIME_PLANNED)) / SUM(WORKFORCETIME) AS DECIMAL(19,3)) AS Planned_Shrink
     , CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS SL_Within_20
     , CAST(1.000*(SUM(CALLS_ANSWERED_INT1)+SUM(CALLS_ANSWERED_INT2)+SUM(CALLS_ANSWERED_INT3)+SUM(CALLS_ANSWERED_INT4)+SUM(CALLS_ANSWERED_INT5)+SUM(CALLS_ANSWERED_INT6)) / SUM(CALLS_OFFERED_ACTUALS) AS DECIMAL(19,3)) AS Calls_Within_60
     , 1-CAST(1.000*(SUM(LCW300)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT1
     , 1-CAST(1.000*(SUM(LCW120)) / SUM(INT_CNT) AS DECIMAL(19,3)) AS LCW_INT2
FROM [GEMDB].[dbo].[v_calls_LCW_Splitday]
WHERE datepart(wk, ROW_DATE) >= (datepart(wk, GETDATE()) - 6) 
  AND datepart(year, ROW_DATE) = 2017
GROUP BY datepart(wk, ROW_DATE)
       , case when DEPARTMENT_DESC in IN ('BILLING', 'TechOps')  
              then 'Customer Service' 
              else DEPARTMENT_DESC end  --((CALLS_ANSWERED_INT1 + CALLS_ANSWERED_INT2) / [CALLS_OFFERED_ACTUALS]) 
ORDER BY datepart(wk, ROW_DATE