Posted by David Portas on 10/08/05 12:48
Any reason why you can't create a permanent Calendar table in your database?
Calendars are useful for many types of query so it makes sense to have one
if you need to do anything with dates.
SELECT cal_date
FROM Calendar
WHERE cal_date BETWEEN @start_date AND @end_date ;
Otherwise, you could write an iterative table-valued function to generate
the data. Unlikely to perform better than a permanent table in most cases
though.
--
David Portas
SQL Server MVP
--
"PromisedOyster" <PromisedOyster@hotmail.com> wrote in message
news:1128748317.108113.292290@g49g2000cwa.googlegroups.com...
> Is there a way that I can get a resultset that contains unique dates in
> a given date range without the need to have a temporary table and a
> cursor?
>
> perhaps something like:
>
> declare @start_date as datetime
> declare @end_date as datetime
> set @start_date as '1/1/2005'
> set @end_date as '1/1/2006'
> select fn_getuniquedate(@start_date, @end_date)
>
>
> 1/1/2005
> 1/2/2005
> 1/3/2005
> ..
> 12/31/2005
>
Navigation:
[Reply to this message]
|