[dba-SQLServer] Series of Sundays in a query

Steve Erbach erbachs at gmail.com
Tue Dec 9 19:05:05 CST 2008


Asger,

I like that solution, too!  A table variable is very elegant. Thank
you very much!

Steve Erbach

On Tue, Dec 9, 2008 at 6:07 PM, Asger Blond <ab-mi at post3.tele.dk> wrote:
> You could use a table variable and a loop like this:
>
> DECLARE @WeekBeginning datetime
> DECLARE @i int
> DECLARE @t table(WeekBeginning char(10))
> SET @i=1
> WHILE @i < 91
> BEGIN
>        SET @i = @i + 7
>        INSERT @t VALUES (CONVERT(char(10),GETDATE() + @i,101))
> END
> SELECT WeekBeginning FROM @t
>
>
> HTH
> Asger
>
>
>
> -----Oprindelig meddelelse-----
> Fra: dba-sqlserver-bounces at databaseadvisors.com
> [mailto:dba-sqlserver-bounces at databaseadvisors.com] På vegne af Steve Erbach
> Sendt: 9. december 2008 23:57
> Til: Discussion concerning MS SQL Server
> Emne: [dba-SQLServer] Series of Sundays in a query
>
> Dear Group,
>
> In an ASP.NET application I'm writing for work, I'd like to create a
> work scheduling web form. One section contains a check box list of all
> employees, another is a radio button list of the different possible
> shifts to choose from, and a third is a checkbox list of "week
> beginning" dates.  The Supervisor checks off all the employees for a
> particular shift, selects the shift, and then selects the weeks that
> those shifts apply.
>
> Anyway, I want to display 13 weeks of "week beginning dates like so:
>
> _ 12/14/2008
> _ 12/21/2008
> _ 12/28/2008
> _ 1/4/2009
> etc.




More information about the dba-SQLServer mailing list