如何使用 SQL 命令在 SQL Server 2005 中打印给定日期的日期名称? [英] How do you print the day name given a day number in SQL Server 2005 using SQL commands?
问题描述
我希望能够传入 1、2、3 或 7 之类的天数,它会返回星期日、星期一、星期二或星期六等日期名称.我知道可以选择使用 case
语句,但我想使用 SQL 命令执行此操作,这可能吗?
I want to be able to pass in a day number like 1, 2, 3 or 7 and it will return the day name like Sunday, Monday, Tuesday or Saturday. I know there is the option of using a case
statement but I would like to do this using SQL commands, would this be at all possible?
DECLARE @m VARCHAR
SET @m=1
SELECT CASE WHEN @m=1 THEN 'Sunday' END
我已经评论过这个问题 在寻找答案时,但用户 @harper 建议我提交一个包含完整描述的新问题.
I have already commented on this question when looking for an answer but user @harper suggested that I should submit a new question with a full description.
目前大多数情况下都给出了案例陈述的答案,除了一个.所以现在我再次提出我的问题是
there is currently answers are given for case statement mostly except one . so again now i am putting my question again here is
我想使用 SQL 命令执行此操作,这可能吗?"
推荐答案
试试这个:
declare @m varchar
set @m=1
SELECT DATENAME(DW,CAST(@m AS INT))
这篇关于如何使用 SQL 命令在 SQL Server 2005 中打印给定日期的日期名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!