Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedure help

Status
Not open for further replies.

michaela18

Technical User
Sep 9, 2009
37
US

I have the following

declare @ActualDate datetime
declare @importdate datetime
declare @DateDiff int
set @DateDiff=datediff(day,@StartDate,@EndDate)
DECLARE @rtDayofWeek VARCHAR(10)


set @DateDiff=@DateDiff+1

while @DateDiff>0
begin

set @ActualDate=@StartDate
set @rtDayofWeek =DATEPART(weekday,@StartDate)
if @rtDayofWeek>=2 and @rtDayofWeek<=5 --Monday to thursday
begin
set @StartDate=dateadd(day,1,@StartDate)
set @importdate=@StartDate
set @DateDiff=@DateDiff-1
insert into @TempOBRMasterData select *,OBR_10_bundle+OBR_Blackberry as 'Total' from Fn_GetOBRMasterDataByimportdate(@importdate,@ActualDate)
end
else
begin
if @rtDayofWeek=6 --Frieday
begin
set @importdate=dateadd(day,3,@StartDate)
insert into @TempOBRMasterData select *,OBR_10_bundle+OBR_Blackberry as 'Total' from Fn_GetOBRMasterDataByimportdateFriday(@importdate,@ActualDate)
set @StartDate=dateadd(day,1,@StartDate)
set @DateDiff=@DateDif




I am having trouble with the dates. The way I run the procedure is :

exec procedure 'date beginning','date ending'

How can I set my procedure for friday where day of week = 6 so that
set @StartDate=dateadd(day,0,@StartDate)

instead of dateadd(day,1,@startdate) because when I change it to 0 i get errors.
 
Why you need it at all?

set @StartDate=dateadd(day,0,@StartDate)

It doesn't make sense to me.
Why should you add ZERO to something and then store the result to the same variable?

Also this is also unnecessary:

set @DateDiff=@DateDiff
WHY?

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Yeah, it looks like not everything got copied when it was pasted.

Also, would you put the code inside the
Code:
 & [/code ] or [tt ] & [/tt ] tags? It makes it a [i]lot[/i] easier to read.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top