sql server - how pivot the days of a month -


I use this question to get the whole day in a month

  Announce @date dateet set @date = '20140201'; Select the day from day to day (as date @, select the day from the date all month (date) = month (date @) * Date from date * Select from date where month (date) = Month (@date)  

and get all days but in a list

how can I get this result, and for example this week this example For:

  Sun1 - Mon1 - TUE1 - WED1 - THU1 - FRI1 - SAT1 - Sun2 - Mon2 - TUE2 - WED2 - THU2 - FRI2 - SAT2 Pd: number corresponding to 1 and 2 weeks   

Is this OK ?? ??

  Announce date @ date setet @date = '20140301'; as with DAYSINMONTH (Select @date as the date, DATENAME (DD, @date) as all DATEADD selection (day, 1, date) as the union on [DAY], DATENAME (weekday, date @) [DAYNAME] , DATENAME (DD, Date as 1 day [day], DATENAME (WEEKDAY, date + 1) from the day of [DAYNAME] in the month where the date (date ) = Select the month (@date)) [1], [2], [3], [4] [5] [6] [7] [8] [9], [10], [11] [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24] ], [25], [26], [27], [28], [29], [30], [31] - Saturday, Sunday, Monday, Tuesday, Wednesday, Thursday, Friday (SELECT [DAY] At the end of the day from [DAYNAME] where the month (date) = month (date @) PIVOT (([1], [2], [3], [4], [5], [6], [7] [8], [9], [10] ([DAYNAME]) MIN ([DAYNAME]]], [11], [12], [13], [14], [15], [16] [27], [28], [17], [18], [19], [20], [21], [22], [23], [24], [25] 29], [30], [31]) as PST  

Another answer for your exact requirement

  Damage to @ date Dettaim declared @lastWeek int set @date = '20140301'; Set @lastWeek = DATENAME (WW, @date) -1; If you choose DAYSINMONTH as (@date date, then DATENAME (DD, @ date) as of [DAY], DATENAME (date of work, date @) + cast (cast (DATENAME (date, date, date) As integral) - as varchar (2)) [DAYNAME] as @ lastWeek on [DAY]] as the union (DATEADD selection dd, 1, date), DATENAME (DD, date + 1) on [DAY] DATENAME (working day, day + 1) + cast (as ite (DATE, WW, date + 1) - @ [vi (2)) as the last week of [DAYNAME] from the end of the day Month (date) = months (@d Nank) Select Sunday 1, Monday 1, Tuesday 1, Wednesday 1, Thursday 1, Friday 1, Saturday 1, Sunday 2, Monday 2, Monday 2, Wednesday 2, Thursday 2, Friday 2, Saturday 2, Sunday 3, Monday 3, Tuesday 3, Wednesday 3, Thursday 3, Friday 3, Saturday 3, Sunday 4, Monday 4, Tuesday 4, Wednesday 4, Thursday 4, Friday4, Saturday4, Sunday5, Monday5, Tuesday5, Wednesday5, Thursday5, Friday5, Saturday5, Sunday 6, Monday6, Tuesday6, Saturday6, Thursday6, Friday6, Saturday6 (select [day], [DAYNAME] DAYSINMONTH where month (date) = from month (@date)) de pivot (max ([Days]) in [DAYNAME] (Sunday1, Monday1, Tuesday1, Wednesday1, Thursday1, Friday1, Saturday1, Sunday2, Monday2, Tuesday2, Wednesday2, Thursday2, Friday2, Saturday2, Sunday3, Monday3, Tuesday3, Wednesday3, Thursday3, Friday3, Saturday3, Sunday4, Monday 4, Tuesday 4, Wednesday 4, Thursday 4, Friday 4, Saturday 4, Sunday 5, Monday 5, Tuesday 5, Wednesday 5, Thursday 5, Friday 5, Saturday 5, Sunday 6, Monday 6 , Tuesday 6, Wednesday 6, Thursday 6, Friday 6, Saturday 6) As PST  

Comments