Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Show Dates by Date range

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2006-06-21 : 23:05:48
My reference on writing this code is from this link
[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=45861&SearchTerms=a[/url]

Here's the code:

declare @DateFrom datetime
declare @DateTo datetime

set @DateFrom = '2006/06/25'
set @DateTo = '2007/12/05'

select dateadd(d, adder.t, @DateFrom) as dayssss
from (
select (i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8) as t
from (select 0 as i1 union select 1) as i1
left join (select 0 as i2 union select 2) as i2 on 1=1
left join (select 0 as i3 union select 4) as i3 on 1=1
left join (select 0 as i4 union select 8) as i4 on 1=1
left join (select 0 as i5 union select 16) as i5 on 1=1
left join (select 0 as i6 union select 32) as i6 on 1=1
left join (select 0 as i7 union select 64) as i7 on 1=1
left join (select 0 as i8 union select 128) as i8 on 1=1
where (i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8) <= datediff(d, @DateFrom, @DateTo)
) as adder
order by dateadd(d, adder.t, @DateFrom)



I want to show the date by date range. Any another approach?
tnx in advance.



Want Philippines to become 1st World COuntry? Go for World War 3...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-06-21 : 23:10:14
[code]select * from dbo.F_TABLE_DATE ( '2006-06-25' , '2007-12-05' )[/code]

Get the F_TABLE_DATE from here


KH

Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2006-06-22 : 00:01:25
another one?

I am currently rewritting the F_TABLE_DATE in MySQL. I want a flexible approach so that i will not be having a hard time for my needs.

Tnx khtan.

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-22 : 04:55:01
Try this


Declare @date table(d datetime)
Declare @DateFrom datetime, @DateTo datetime

set @DateFrom = '2006/06/25'
set @DateTo = '2007/12/05'

While @DateFrom<=@DateTo
Begin
Insert into @date values (@DateFrom)
set @DateFrom=@DateFrom+1
End
Select d from @date


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -