Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

SQL
;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
Posted
Updated 3-Oct-17 1:10am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900