You are here: Re: Run same query for each day across a date range? « MsSQL Server « IT news, forums, messages
Re: Run same query for each day across a date range?

Posted by Ed Murphy on 05/14/07 09:45

Gooseman wrote:

> I have a query which works for one day:
>
> SELECT SOME_COL AS something, SOME_COL2 AS something2 FROM myTable
> WHERE DATE = '2007-05-11' AND SOME_STAT > 1
>
> Returns
>
> something something 2
> 1 2
> 3 4
>
> How do I get this to work for a date range (e.g. DATE > '2007-05-09')
> where I get:
>
> date something something2
> 2007-05-09 1 2
> 2007-05-09 3 4
> 2007-05-10 1 2
> 2007-05-10 3 4
> 2007-05-11 1 2
> 2007-05-11 3 4

I think the usual method is to create a table containing all dates
that you're likely to ever use, then cross-join to it.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация