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 |
|
vmurali
Yak Posting Veteran
88 Posts |
Posted - 2007-05-29 : 07:12:54
|
| declare @start datetime,@end datetimeselect @start='1/2/2007',@end='1/31/2007'select datediff(dd,@start,@end)-count(*) as weekdays from weekendsandholidays where dayofweekdate between @start and @endex;u take two dates 1/2/2007,1/31/2007 note:actually diff between 1/2/2007 and 1/31/2007 is 31 now u run above query then we can get answer count of remaining dates as 29 but i dont want the count 29I want remaining days list one after one |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-29 : 07:16:49
|
| not clear.. please post some sample data and output u want |
 |
|
|
vmurali
Yak Posting Veteran
88 Posts |
Posted - 2007-05-29 : 07:29:37
|
| If there are 2 dates 1/2/2007,1/31/2007The dates in holidays list are 1/5/2007,1/15/2007Now actually diff between 1/2/2007 and 1/31/2007 is 31Now when I run my queryselect datediff(dd,@start,@end)-count(*) as weeksays from weekendsandholidays where dayofweekdate between @start and @endI get the count as 29.But I want the result as 1/3/20071/4/20071/6/2007....1/31/2007excluding the 1/5/2007,1/15/2007 |
 |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2007-05-29 : 07:36:38
|
quote: Originally posted by vmurali If there are 2 dates 1/2/2007,1/31/2007The dates in holidays list are 1/5/2007,1/15/2007Now actually diff between 1/2/2007 and 1/31/2007 is 31Now when I run my queryselect datediff(dd,@start,@end)-count(*) as weeksays from weekendsandholidays where dayofweekdate between @start and @endI get the count as 29.But I want the result as 1/3/20071/4/20071/6/2007....1/31/2007excluding the 1/5/2007,1/15/2007
select datediff(dd, '01/02/2007', '01/31/2007') as diffo/pdiff29Mahesh |
 |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2007-05-29 : 07:42:13
|
| to exclude the holidays tryselect datediff(dd,@start,@end)-count(*) as weeksays from weekendsandholidays where dayofweekdate between @start and @endand dayofweekdate not in (<holiday list>)thanks,Mahesh |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-29 : 07:45:55
|
| this just a sample u change it however u wantdeclare @start datetime, @end datetimedeclare @weekend table(dt datetime)Insert @weekend Select '01/05/2007' union allselect '01/15/2007'Set @start = '01/02/2007'Set @end = '01/31/2007'Select * from (select date = dateadd(day,number,@start) from master..spt_values where name is null and type='P' and number > 0 and number <= (datepart(day, @end) - datepart(day,@start))) as bwhere date not in (select dt from @weekend) |
 |
|
|
vmurali
Yak Posting Veteran
88 Posts |
Posted - 2007-05-29 : 08:26:39
|
| Actually I want to exclude in final output of the queryMy output should be like :1/2/20071/3/20071/4/20071/6/2007.... |
 |
|
|
pbguy
Constraint Violating Yak Guru
319 Posts |
Posted - 2007-05-29 : 08:29:46
|
| did u try what i posted.. |
 |
|
|
|
|
|
|
|