Advertisement
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: |
--Declare Start and End variables (these can also be passed into a stored procedure)
DECLARE @startdate smalldatetime,
@endDate smalldatetime
--this drops the hours and minutes and sets them to 00:00
Set @startdate = convert(varchar,'Nov 1, 2008' ,111)
Set @endDate = convert(varchar,'Dec 31 2008' ,111)
--Declare EnD Date tmp variable to be used in the loop
DECLARE @tmpEndDate smalldatetime
--Declare tmp table to act as a temporary holding place for your data
DECLARE @tmpTable TABLE(
StartDate smalldatetime,
EndDate smalldatetime,
noemp integer)
--Set @startdate to beginning of month span
Set @startdate = DATEADD(dd,-(DAY(DATEADD(m,1,@startdate))-1),@startdate)
--set @endDate to end of month span
Set @endDate = DATEADD(dd, -DAY(DATEADD(m,1,@endDate)), DATEADD(m,1,@endDate))
--loop through each month
While @startdate < @endDate
BEGIN
--set @tmpEndDate to last minute of month
Set @tmpEndDate = dateadd(n,-1,dateadd(m,1,@startdate))
--insert values in table
Insert into @tmpTable(StartDate,EndDate,noemp)
Select @startdate as startdate, @tmpEndDate as enddate, NoEmployees as noemp
from CTContracts
Where Fromdate <= @tmpEndDate And EndDate >= @startdate
and LKContractTypeID = 8
--increment @startdate
Set @startdate = dateadd(m,1,@startdate)
END
--Now you can do what you want with the results
Select * from @tmpTable
Select Min(StartDate) as StartDate, Max(EndDate) as EndDate, Sum(noemp) as noemp from @tmpTable
|
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
|
Loading Advertisement... |