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 |
|
gangadhara.ms
Aged Yak Warrior
549 Posts |
Posted - 2009-09-29 : 12:26:56
|
| Dear All,I am new to SQL server programming i need to write a function that returns the interger and accepts the 2 dates between those 2 days i need to count the number of days Except the week ends.Can somebody help me. |
|
|
gangadhara.ms
Aged Yak Warrior
549 Posts |
Posted - 2009-09-29 : 12:47:10
|
| Dear All,Pls let me know how to execute the SQL server Function ? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-09-29 : 12:58:01
|
| [code]CREATE FUNCTION GetWorkingDays(@Start datetime,@End datetime)RETURNS int ASBEGIN DECLARE @WorkDays intSELECT @WorkDays=COUNT(1)FROM(SELECT DATEADD(dd,number,@Start) AS DateFROM master..spt_valuesWHERE type='p'AND DATEADD(dd,number,@Start)<=@EndAND DATENAME(dw,DATEADD(dd,number,@Start)) NOT IN ('Saturday','Sunday'))tRETURN @WorkDaysENDexecute it likeSELECT dbo.GetWorkingDays('01-03-2009','01-07-2009')[/code] |
 |
|
|
|
|
|