问题描述:

I am trying to find the week of quarter from a cal_date_d table using sql. My table has cal_date, fiscal quarter start and end date. I also have a column which has the fiscal_week_of_year. and my fiscal year starts from feb.

However the closest query i've got to resolve this issue is below:

select datepart(week, DATEADD(MONTH,-10,cal_date)) - ((DatePart(quarter, DATEADD(MONTH,-10,cal_date))-1) *13),

fiscal_week_of_year,

weekofqtr,

cal_date

from cal_date_d_tst

Now the first week result i am always getting is 0. I am not sure where I am going wrong.

help me out on this one..

网友答案:

If you have fiscal_quarter_start, then doesn't this work?

select 1 + datediff(day, fiscal_quarter_start, cal_date) / 7 

This just calculates the number of days into the quarter and divides by 7.

相关阅读:
Top