Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Create Procedure State_12MC_SFC_Proc
As Begin
declare @SQL nvarchar(max), @Cols nvarchar(max)
set @Cols = stuff((select ', ' + quotename(Period_no)
from (select distinct Period_no from REAS_HPI_State_Final where Period_no>=193) X
order by Period_no desc for XML PATH('')),1,2,'')
set @SQL = 'Select DISTINCT R.STATE_NAME, pvt.*
INTO #Temp
from
(select state_code,Period_no, HPI_12M_Change*100 as [Percents] from REAS_HPI_STATE_Final where tier_code in(0)
) src
PIVOT
( max([Percents]) For Period_no IN( '+@Cols +')) as Pvt
INNER JOIN REAS_STATE_BE r
ON pvt.STATE_CODE = R.STATE_Code'
execute (@SQL)
END;
Alter Procedure State_12MC_SFC_Proc
As Begin
declare @SQL nvarchar(max), @Cols nvarchar(max)
Begin
If object_id('Results','U') is not null drop table Results
set @Cols = stuff((select ', ' + quotename(Period_no)
from (select distinct Period_no from REAS_HPI_State_Final where Period_no>=193) X
order by Period_no desc for XML PATH('')),1,2,'')
set @SQL = 'Select DISTINCT R.STATE_NAME, pvt.*
INTO Results
from
(select state_code,Period_no, HPI_12M_Change*100 as [Percents] from REAS_HPI_STATE_Final where tier_code in(0)
) src
PIVOT
( max([Percents]) For Period_no IN( '+@Cols +')) as Pvt
INNER JOIN REAS_STATE_BE r
ON pvt.STATE_CODE = R.STATE_Code'
execute (@SQL)
End;
END;