suppose the fiscal year is starting from July/1st to June/30th.
I have to calculate the week no. accordingly in SQL Server 2005.
Please Suggest!
Many Tha
Without the need of creating a table. Just replace the @date with your column date name
declare @date datetime
set @date = '12/8/2016 00:00:00'
select case when datepart(month,@date) > 6 then
case when CEILING(datediff(day,'6/30/' + cast(datepart(year,@date) as nvarchar(4)),@date) / 7.0) > 52
then 52 else CEILING(datediff(day,'6/30/' + cast(datepart(year,@date) as nvarchar(4)),@date) / 7.0) end
else
case when CEILING(datediff(day,'6/30/' + cast(datepart(year,@date)-1 as nvarchar(4)),@date) / 7.0) > 52
then 52 else CEILING(datediff(day,'6/30/' + cast(datepart(year,@date)-1 as nvarchar(4)),@date) / 7.0) end
end WorkWeek
Compute Week number based on Fiscal Year