Hi

Finally, some (possibly silly) people have let me get my mits on MS Sql Server databases.
Where, with only the experience of MS Access and examples (previously) from here and online, I get to wade in with big boots.

Ok so the basics are the same for querying, table structures are a little different and sub queries tend not to do as I thought. However ...


Yesterday I wanted to get a list of dates thirty (30) days in the past to now. But I don't want to create a table, at least not in the sense of writing; storing and populating it. So I searched online and found a chunk of code. After discussing here with a colleague I ended up with the SQL below.

But how does it work.?
I get the gist, start date, loop each day, it's just how it does it without an explicit loop...

Could some one please answer this really easy question??


Code:
with T(day) as
(
    select DATEADD(dd,-30,DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)) as day
        union all
    select day + 1
        from T
        where day < DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
)
select * from T