码迷,mamicode.com
首页 > 数据库 > 详细

sql2008 日期

时间:2014-09-04 18:54:49      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:blog   http   ar   2014   art   log   on   c   sql   

Declare @Begindate Date;

set @Begindate = getdate()


Select
cast(Convert(varchar(10),cast(@Begindate as date),112) as int) As Datekey,
Year(@Begindate) As Year,
Datepart(Quarter,@Begindate) As Que,
Case
When Datepart(Quarter,@Begindate) = 1 Then ‘第一季度‘
When Datepart(Quarter,@Begindate) = 2 Then ‘第二季度‘
When Datepart(Quarter,@Begindate) = 3 Then ‘第三季度‘
Else ‘第四季度‘
End As QueCN,
Month(@Begindate) As Month,
Case
When Month(@Begindate) = 1 Then ‘一月‘
When Month(@Begindate) = 1 Then ‘二月‘
When Month(@Begindate) = 1 Then ‘三月‘
When Month(@Begindate) = 1 Then ‘四月‘
When Month(@Begindate) = 1 Then ‘五月‘
When Month(@Begindate) = 1 Then ‘六月‘
When Month(@Begindate) = 1 Then ‘七月‘
When Month(@Begindate) = 1 Then ‘八月‘
When Month(@Begindate) = 1 Then ‘九月‘
When Month(@Begindate) = 1 Then ‘十月‘
When Month(@Begindate) = 1 Then ‘十一月‘
Else ‘十二月‘
End As MonthCN,
Case
When Datepart(Day,@Begindate) <= 10 Then ‘1‘
When Datepart(Day,@Begindate) > 20 Then ‘3‘
Else ‘2‘
End As Ten,
Case
When Datepart(Day,@Begindate) <= 10 Then ‘上旬‘
When Datepart(Day,@Begindate) > 20 Then ‘下旬‘
Else ‘中旬‘
End As TenCN,
Datepart(Week,@Begindate) As Week,
Cast(Datepart(Week,@Begindate) As Char(2)) + ‘周‘ As WeekCN,
Datename(Weekday,@Begindate) As WeekDay,
Day(@Begindate) As Day,
Convert(Varchar(20),@Begindate,23) As DateTime

bubuko.com,布布扣

sql2008 日期

标签:blog   http   ar   2014   art   log   on   c   sql   

原文地址:http://www.cnblogs.com/figo--fiona/p/3956541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!