Click here to Skip to main content
16,018,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using This query how get like Calendar type Table like


Sunday	Monday	Tuesday	Wednesday Thursday Friday Saturday
                    1     2         3        4       5
6          7        8     9        10      11      12
13        14
.......


SQL
Declare @Month as int =2010, @Year As int =1

SELECT * from (
SELECT
	cast('01' AS varchar) + Number AS [CurDate],
	DAteName(WEEKDAY, cast('01' AS varchar) + Number) AS [MyName]
	
FROM master..spt_values
WHERE type = 'P' 

AND
(CAST(CAST(@year AS VARCHAR) + '-' + CAST(@Month AS VARCHAR) + '-01' AS DATETIME) + Number )
<
DATEADD(mm,1,CAST(CAST(@year AS VARCHAR) + '-' + CAST(@Month AS VARCHAR) + '-01' AS DATETIME))

) k
pivot 
(
	min(CurDate) for MyName in (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday) 
)k1
Posted
Updated 9-Jan-16 6:44am
v2

1 solution

Don't.
Those are presentation functions, not data retrieval - if nothing else, the month and day names will depend on the client's culture settings - which the SQL server computer is very unlikely to have access to.

Use presentation controls or reports to generate calendar based data, not SQL.
 
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