SQL Server Note

年月日時分秒を個別に取得

SELECT NAME,BUYDATE, 
YEAR(BUYDATE) AS [YY],
MONTH(BUYDATE) AS [MM],
DAY(BUYDATE) AS [DD],
DATEPART(HOUR, BUYDATE)  AS [HH],
DATEPART(MINUTE, BUYDATE)  AS [MI],
DATEPART(SECOND, BUYDATE)  AS [SS]
FROM PC
NAMEBUYDATEYYMMDDHHMISS
CL-BAD1900-01-01 00:00:00.000190011000
CL-NONENULLNULLNULLNULLNULLNULLNULL
CL-SAITO2000-03-15 14:10:05.000200031514105
CL-SHARE1995-06-13 00:00:00.0001995613000
CL-UEDA2001-01-11 18:20:15.0002001111182015
CL-YOSHIDA2000-03-12 00:00:00.0002000312000
SV-FILE2000-08-01 00:00:00.000200081000
SV-MAIL1999-12-16 13:50:52.00019991216135052
SV-WEB2001-01-11 01:03:18.00020011111318

上記ではYEAR、MONTH、DAYといった関数を使用しましたが、年月日もDATEPARTで取得することができます。

Copyright © 2006 Hikijishi All Rights Reserved.
[] [sql][0.0016179084777832]