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 |
|
avmreddy17
Posting Yak Master
180 Posts |
Posted - 2008-07-31 : 22:25:40
|
| I have a table with holiday date as ColumnHoliday Date2008-08-04 00:00:00.0002008-09-01 00:00:00.0002008-10-13 00:00:00.0002008-12-25 00:00:00.000I just want to pass the current date (Say T) and get a date (T+3) skipping Sunday,Saturday and any days in the Holiday table.I have a Stored Proc which does this, but just wandering if there is way to just write it with a simple select staementIf I run today ( JULY 31 ) , T+3 shud return 08/06/2008 Skiping Sat and Sunday and skipping 08/04 from the Holiday table also look into Thx |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-08-01 : 02:01:42
|
| Hi,Try with this. May be this will help to u .Declare @StartDate datetime ,@EndDate datetime , @Fromdate DatetimeSelect @FromDate = '08/1/2008'Select @StartDate = CONVERT(varchar(10),DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()),120)SELECT @EndDate = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))SELECT DATEADD(day,number,@StartDate) as 'Dates', datename( dw,DATEADD(day,number,@StartDate)) 'DayName' into #TempFROM master..spt_valuesWHERE type='p' AND number BETWEEN 0 AND DATEDIFF(day,@StartDate,@EndDate)ORDER BY 1Declare @Temp Table (Dates Datetime)Insert into @TempSelect Dates From #Temp where DayName <> 'Sunday' and DayName <> 'Saturday' Declare @Table Table (HolidayDate datetime)Insert into @TableSelect '2008-08-04 00:00:00.000' Union AllSelect '2008-09-01 00:00:00.000' Union AllSelect '2008-10-13 00:00:00.000' Union AllSelect '2008-12-25 00:00:00.000' Select DatesFrom (Select Dates, ROW_NUMBER()OVER ( ORDER BY DATES) AS 'ROW' From @Temp where Dates Not in (Select HolidayDate From @Table)AND Dates > @FromDate ) Dwhere Row = 3 Drop Table #Temp |
 |
|
|
|
|
|
|
|