retrieving 3 working days
-
ALTER procedure [dbo].[sp_pubhol]
as
begin
declare @i int
declare @NewDate date
set @i = 0
while(@i<3)
begin
IF DATEPART(dw, DATEADD(day,@i,CONVERT(date,GETDATE()))) = 7 OR DATEPART(dw, DATEADD(day,@i,CONVERT(date,GETDATE()))) = 1
print 'weekend'
else
print 'weekday'select Holiday_Name from Holiday where Holiday_On = DATEADD(day,@i,CONVERT(date,GETDATE()))
SELECT @NewDate = DATEADD(DAY,@i,CONVERT(date,GETDATE()))
RETURN @NewDate
select @i = @i+1
end
endmy task is if today is neither weekend nor public holiday ,i have to that date, increment loop...i have retrieve all the 3 working days...can anyone help me pls if i want declare @NewDate as array[[3] ,how to declare that..pls help me
-
ALTER procedure [dbo].[sp_pubhol]
as
begin
declare @i int
declare @NewDate date
set @i = 0
while(@i<3)
begin
IF DATEPART(dw, DATEADD(day,@i,CONVERT(date,GETDATE()))) = 7 OR DATEPART(dw, DATEADD(day,@i,CONVERT(date,GETDATE()))) = 1
print 'weekend'
else
print 'weekday'select Holiday_Name from Holiday where Holiday_On = DATEADD(day,@i,CONVERT(date,GETDATE()))
SELECT @NewDate = DATEADD(DAY,@i,CONVERT(date,GETDATE()))
RETURN @NewDate
select @i = @i+1
end
endmy task is if today is neither weekend nor public holiday ,i have to that date, increment loop...i have retrieve all the 3 working days...can anyone help me pls if i want declare @NewDate as array[[3] ,how to declare that..pls help me
Use a table variable not an array.
Declare @Tbl Table(Date datetime)
Insert @tTbl
Select getdate()So instead of buying a book and studying you are going to bring every problem to the interweb forums for answer. I predict your questions shortly be ignored and no answers will be forth coming!
Never underestimate the power of human stupidity RAH