在SQL Server中创建日历表 [英] Create a calendar table in SQL server
本文介绍了在SQL Server中创建日历表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好每一个
我想在sql server中创建一个日历表。所以我需要一个月和一年的列数。喜欢给定的月份10/2017
1 | 2 | --------- | 31 |
我尝试过:
我有疑问列出一个月的所有日子但是如下所示的行
Hello every one
I am trying to create a calendar table in sql server. So i need columns of days for a given month and year. Like for the given month 10/2017
1 | 2 | --------- | 31 |
What I have tried:
I have a query for listing all days for a month but in rows like below
;WITH N(N)AS
(SELECT 1 FROM(VALUES(1),(1),(1),(1),(1),(1))M(N)),
tally(N)AS(SELECT ROW_NUMBER()OVER(ORDER BY N.N)FROM N,N a)
SELECT N day FROM tally
WHERE N <= day(EOMONTH(datefromparts(2017,10,1)))
但不知道如何将其转换为带有枢轴的列
提前感谢
but don't know how to convert that to column with pivot
thanks in advance
推荐答案
As我早些时候已经向其他人提出过建议。
请在去特定论坛之前谷歌你的问题(这就是我做的)。
编程社区是如此之大,很有可能某个机构已经面临你现在面临的问题,因此该问题的解决方案也应该存在。
请关注这个链接并从那里获取。
祝你有个美好的一天。
As I have advised earlier to other people.
Please google your problem (which is what I did) before going to a specific forum.
The programming community is so big, there is a good chance that some body has already faced the problem you are facing right now, so a solution for that problem should also be there.
Please follow this link and take it from there.
Have a good day.
这篇关于在SQL Server中创建日历表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文