如何从订单日期获取当前日期以获得预期天数老化数字

时间:2017-04-12 20:18:39

标签: sql

更新 我想通了,抱歉之前缺乏细节。我必须转换日期,所以它显示04/12/2017而不是原来的20170412,然后每天分解。

  SELECT
  PHPICK00.PHORDT "Days Aging",
  COUNT(DISTINCT(PHPICK00.PHPKTN)) "Total Orders"
  FROM
  PHPICK00
  WHERE
   PHPICK00.PHORDT>= 0  
  GROUP BY
   PHPICK00.PHORDT   SELECT COUNT(PHPCTL) "Orders",                                  
  CASE When                                                     
   SUBSTR(DIGITS(PHSTDT),6,2)||'/'||                                                       
   SUBSTR(DIGITS(PHSTDT),8,2)||'/'||                                                       
   SUBSTR(DIGITS(PHSTDT),2,4) = current date -1 days then '1 Day'
  when                                                          
   SUBSTR(DIGITS(PHSTDT),6,2)||'/'||                                                       
   SUBSTR(DIGITS(PHSTDT),8,2)||'/'||                                                       
   SUBSTR(DIGITS(PHSTDT),2,4) = current date -2 days then '2 Day'
  when                                                          
   SUBSTR(DIGITS(PHSTDT),6,2)||'/'||                                                       
   SUBSTR(DIGITS(PHSTDT),8,2)||'/'||                                                             
   SUBSTR(DIGITS(PHSTDT),2,4) = current date -3 days then '3 Day'      
  when                                                                
   SUBSTR(DIGITS(PHSTDT),6,2)||'/'||                                                             
   SUBSTR(DIGITS(PHSTDT),8,2)||'/'||                                                             
   SUBSTR(DIGITS(PHSTDT),2,4) = current date -3 days then '4+ Days'
   else 'Ship Start Date Not Yet Met' END AS "Days Aging"                                       

  FROM PHPICK00                                                       
  WHERE PHPSTF < '90' AND PHSTDT > 0

我试图让return语句显示每个订单的日期。我能够检索的所有日期都是通用格式&#34; 20170412&#34;,而我希望它输出&#34; 1&#34;,&#34; 2&#34;,&#34 ; 3&#34;等。

我对SQL很新!希望这是一个简单的解决方案。

SELECT
  PHPICK00.PHORDT "Order Date",
  COUNT(DISTINCT(PHPICK00.PHPKTN)) "Total Orders"
FROM PHPICK00
WHERE PHPICK00.PHORDT = PHPICK00.PHORDT - GETDATE()
GROUP BY PHPICK00.PHORDT   
ORDER BY PHPICK00.PHORDT DESC

1 个答案:

答案 0 :(得分:0)

我想你想要这个 - 有点难以分辨。可能希望在你的问题中更清楚。

DATEDIFF(day,PHPICK00.PHORDT,GETDATE())