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 |
|
govindts
Starting Member
33 Posts |
Posted - 2009-01-15 : 18:12:33
|
| Sorry for asking very basic questions.. I am not a sqlserver guy.I wanted to execute one userdefined function. How can i execute the function. I thought, i call this function through select statement.. But it did not work...I just wanted to execute this function...I tried SELECT ADDBUSINESSDAYS(GETDATE(),2)But it did not work. Any help is appreciated....CREATE FUNCTION [dbo].[AddBusinessDays]( @StartDate DATETIME, @NumberOfDays INT)RETURNS DATETIMEAS/*1 = Sonntag2 = Montag3 = Dienstag4 = Mittwoch5 = Donnerstag6 = Freitag7 = Samstag*/BEGIN DECLARE @CurrentWeekday INT; DECLARE @FullWeeks INT; SET @CurrentWeekday = DATEPART(dw,@StartDate); IF @CurrentWeekday = 2 BEGIN SET @StartDate = DATEADD(d,4,@StartDate) SET @NumberOfDays = @NumberOfDays - 4 END IF @CurrentWeekday = 3 BEGIN SET @StartDate = DATEADD(d,3,@StartDate) SET @NumberOfDays = @NumberOfDays - 3 END IF @CurrentWeekday = 4 BEGIN SET @StartDate = DATEADD(d,2,@StartDate) SET @NumberOfDays = @NumberOfDays - 2 END IF @CurrentWeekday = 5 BEGIN SET @StartDate = DATEADD(d,1,@StartDate) SET @NumberOfDays = @NumberOfDays - 1 END IF @NumberOfDays > 0 BEGIN SET @FullWeeks = @NumberOfDays / 5 WHILE (@FullWeeks) > 0 BEGIN SET @NumberOfDays = @NumberOfDays - 5 IF @NumberOfDays > 0 BEGIN SET @StartDate = DATEADD(d,7,@StartDate) END ELSE BEGIN SET @StartDate = DATEADD(d,5,@StartDate) END SET @FullWeeks = @FullWeeks - 1 END SET @StartDate = DATEADD(d,@NumberOfDays+2,@StartDate) END IF @NumberOfDays < 0 BEGIN SET @StartDate = DATEADD(d,@NumberOfDays,@StartDate) END RETURN @StartDate;END |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|