查詢日期轉為民國年,有時候資料需要前面加0,利用RIGHT與CAST配合
PRINT 'CAST : '
+ RIGHT(CAST(1000+ DATEPART(yy, getdate())-1911 AS CHAR(4)),3)+'-'
+ RIGHT(CAST(100 + DATEPART(MM, getdate()) AS CHAR(3)), 2) +'-'
+ RIGHT(CAST(100 + DATEPART(DD, getdate()) AS CHAR(3)), 2) +' '
+ RIGHT(CAST(100 + DATEPART(HH, getdate()) AS CHAR(3)), 2) +':'
+ RIGHT(CAST(100 + DATEPART(MI, getdate()) AS CHAR(3)), 2) +':'
+ RIGHT(CAST(100 + DATEPART(SS, getdate()) AS CHAR(3)), 2)
--------print--------------
/**
CAST : 101-01-18 11:28:38
**/
沒有留言:
張貼留言