从SQL Server 2012中的WeekDay整数获取WeekDay名称 [英] Get WeekDay Name from WeekDay integer in SQL Server 2012

查看:43
本文介绍了从SQL Server 2012中的WeekDay整数获取WeekDay名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅使用T-SQL而不使用CASE语句来获得知道星期几整数值的星期几名称?

How can I get the week day name knowing the week day integer value using only T-SQL and without using CASE statement?

例如,如果星期几的整数值为2,那么我需要获取"Monday"作为星期几的名称.

For example, if week day integer value is 2, then I need to get 'Monday' as week day name.

declare @currentDate as DATETIME;
set @currentDate = getdate();
SELECT DATEPART(dw, @currentDate) as WeekDayIntegerValue,
       '' as WeekDayName --i need the t-sql to use for this column

推荐答案

您应该为此使用DATENAME. https://msdn.microsoft.com/en-us/library/ms174395.aspx

You should use DATENAME for this. https://msdn.microsoft.com/en-us/library/ms174395.aspx

declare @currentDate as DATETIME;
set @currentDate = getdate();
SELECT DATEPART(dw, @currentDate) as WeekDayIntegerValue,
       DATENAME(weekday, @currentDate) as WeekDayName 
       --i need the t-sql to use for this column

此外,您还应该养成不使用日期函数快捷方式的习惯.

Also, you should get out of the habit of not using the shortcuts to the date functions.

这篇关于从SQL Server 2012中的WeekDay整数获取WeekDay名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆