PreviousQuarterApril 19, 2004
>>Script Language and Platform: SQL Server 2000 Author: The MAK
Create function dbo.previousquarter (@date datetime)
returns datetime
as begin
--Author -MAK
--Objective-- To return the first day of previous quarter of a given date
declare @month tinyint
declare @year int
declare @returndate datetime
if month(@date) between 1 and 3 begin set @month=10 set @year=year(@date)-1 end
if month(@date) between 4 and 6 begin set @month=1 set @year=year(@date) end
if month(@date) between 7 and 9 begin set @month=4 set @year=year(@date) end
if month(@date) between 10 and 12 begin set @month=7 set @year=year(@date) end
--print @month
--print @year
set @returndate = convert(datetime,right('00'+convert(varchar(2),@month),2)
+'/01/'+convert(varchar(4),@year))
return @returndate
end
Disclaimer: We hope that the information on these script pages is
valuable to you. Your use of the information contained in these pages,
however, is at your sole risk. All information on these pages is provided
"as -is", without any warranty, whether express or implied, of its accuracy,
completeness, or fitness for a particular purpose...
Disclaimer Continued
Back to Database Journal Home |