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.
| Author |
Topic |
|
BlackDog
Starting Member
18 Posts |
Posted - 2005-01-21 : 14:28:41
|
| Given a begin date and an end date, I need to select all dates that fall within that range. For example, there is a table with a BeginDate column and EndDate column. One row in that column has the values of '1/1/2005' for BeginDate and '1/5/2005' for EndDate.I need a result set that lists:1/1/20051/2/20051/3/20051/4/2005Any ideas? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-01-21 : 15:16:28
|
| BlackDog, something like this might do. (the @numbers table could be any existing table with an unbroken chain of integers):declare @numbers table (number int)Declare @Dates Table (FromDate datetime ,ToDate datetime)set nocount oninsert @Datesvalues ('1/1/2005', '1/5/2005')--===================================--add a bunch of numbersdeclare @i intset @i = 1while @i < 1000Begin insert @numbers values (@i) Select @i = @i + 1End--===================================SElect convert(varChar(15), dateAdd(day, number-1, fromdate), 101)from @datescross join @numbersWhere dateDiff(day,fromdate,todate) >= number |
 |
|
|
BlackDog
Starting Member
18 Posts |
Posted - 2005-01-21 : 15:56:21
|
| That might do rather well. Thanks! I did change the arbitrary 1000 rows to use the number of days between the begin and end date, but works good.If any one else has another method, please post. Thanks. |
 |
|
|
|
|
|
|
|