HI All,
I want Automate rolling quarter logic permanently. We are loading the data every quarter and based upon billing date and paid updating the year value .Instead of adding new statement manually is there any way to automate this code for every quarter for ongoing process… and please check below sql and help me to automate the code
april 2
UPDATE TABLEASETYEAR= casewhen[b1].[BILLING_DATE]between'1/1/2013'and'12/31/2013'
and[PAID_DATE]between'1/1/2013'and'3/31/2014' then'2013'
when[b1].[BILLING_DATE]between'1/1/2010'and'12/31/2010'
and[PAID_DATE]between'1/1/2010'and'3/31/2011' then'2010'
when[b1].[BILLING_DATE]between'1/1/2011'and'12/31/2011'
and[PAID_DATE]between'1/1/2011'and'3/31/2012' then'2011'
when[b1].[BILLING_DATE]between'1/1/2012'and'12/31/2012'
and[PAID_DATE]between'1/1/2012'and'3/31/2013' then'2012'
else'9999'end
WHEREyearis null
July 2
UPDATE TABLEASETYEAR=case
when[b1].[BILLING_DATE]between'4/1/2013'and'3/31/2014'
and[PAID_DATE]between'4/1/2013'and'6/30/2014' then'2013'
when[b1].[BILLING_DATE]between'4/1/2010'and'3/31/2011'
and[PAID_DATE]between'4/1/2010'and'6/30/2011' then'2010'
when[b1].[BILLING_DATE]between'4/1/2011'and'3/31/2012'
and[PAID_DATE]between'4/1/2011'and'6/30/2012' then'2011'
when[b1].[BILLING_DATE]between'4/1/2012'and'3/31/2013'
and[PAID_DATE]between'4/1/2012'and'6/30/2013' then'2012'
else'9999'end
WHEREyearis null
Oct 2
UPDATE TABLEASETYEAR=case
when[b1].[BILLING_DATE]between'7/1/2013'and'6/30/2014'
and[PAID_DATE]between'7/1/2013'and'9/30/2014' then'2014'
when[b1].[BILLING_DATE]between'7/1/2010'and'6/30/2011'
and[PAID_DATE]between'7/1/2010'and'9/30/2011' then'2011'
when[b1].[BILLING_DATE]between'7/1/2011'and'6/30/2012'
and[PAID_DATE]between'7/1/2011'and'9/30/2012' then'2012'
when[b1].[BILLING_DATE]between'7/1/2012'and'6/30/2013'
and[PAID_DATE]between'7/1/2012'and'9/30/2013' then'2013'
else'9999'end
WHEREyearis null
Jan 2
UPDATE TABLEASETYEAR=case
when[b1].[BILLING_DATE]between'10/1/2013'and'9/30/2014'
and[PAID_DATE]between'10/1/2013'and'12/31/2014' then'2014'
when[b1].[BILLING_DATE]between'10/1/2010'and'9/30/2011'
and[PAID_DATE]between'10/1/2010'and'12/31/2011' then'2011'
when[b1].[BILLING_DATE]between'10/1/2011'and'9/30/2012'
and[PAID_DATE]between'10/1/2011'and'12/31/2012' then'2012'
when[b1].[BILLING_DATE]between'10/1/2012'and'9/30/2013'
and[PAID_DATE]between'10/1/2012'and'12/31/2013' then'2013'
else'9999'end
WHEREyearis null
Thanks
CMK..