[SQL ] 判斷時間,如何判斷0此項目

作者: yes302 (TOMMY)   2014-02-12 11:08:24
小弟有個很笨T-SQL的問題
以前做過...但怎麼想也想不起來
目前所擁有的SQL為
SELECT
Count(*) AS CNT
,DATEPART(WK, CreateTime) AS WK
,YEAR(CreateTime) AS Y
,Month(CreateTime) AS M
,DATEPART(DD, CreateTime) AS DD
,CASE
WHEN DATEPART(DW,CreateTime)-1 =0 THEN '(日)'
WHEN DATEPART(DW,CreateTime)-1 =1 THEN '(一)'
WHEN DATEPART(DW,CreateTime)-1 =2 THEN '(二)'
WHEN DATEPART(DW,CreateTime)-1 =3 THEN '(三)'
WHEN DATEPART(DW,CreateTime)-1 =4 THEN '(四)'
WHEN DATEPART(DW,CreateTime)-1 =5 THEN '(五)'
WHEN DATEPART(DW,CreateTime)-1 =6 THEN '(六)'
END
AS DW
,DATEPART(HH, CreateTime) AS HH
FROM
XTable
GROUP BY
YEAR(CreateTime)
,Month(CreateTime)
,DATEPART(WK, CreateTime)
,DATEPART(DD, CreateTime)
,DATEPART(DW,CreateTime)
,DATEPART(HH, CreateTime)
ORDER BY
作者: smlboby (波比)   2014-02-12 15:56:00
union all 一筆5點擊進去?
作者: yes302 (TOMMY)   2014-02-12 18:10:00
這樣就寫死了...有活一點的方式嗎?

Links booklink

Contact Us: admin [ a t ] ucptt.com