select g.bill_no, g.PREV_VAL, G.RETURN_VAL, wg.prev_val, wg.curr_val, wg.return_val , g.owner_name, wg.lastname, WG.PERSKEY 
	, convert(int,g.ST_VALUE1 )
	+ convert(int,g.ST_VALUE2 )
	+ convert(int,g.ST_VALUE3 )
	+ convert(int,g.ST_VALUE4 )
	+ convert(int,g.ST_VALUE5 )
	+ convert(int,g.ST_VALUE6 )
	+ convert(int,g.ST_VALUE7 )
	+ convert(int,g.ST_VALUE8 )
	+ convert(int,g.ST_VALUE9 )
	+ convert(int,g.ST_VALUE10) GSI_CURR_VAL
	, wg.CURR_VAL 
from MCDUFFIE_GSI.dbo.PARCEL g
INNER join (
	SELECT REPLACE(O.LASTNAME,',','') AS LASTNAME, O.ADDRESS1, O.ADDRESS2, O.ADDRESS3, O.CITY, O.STATE, O.ZIP
		, P.PERSKEY, P.PREV_VAL, P.CURR_VAL, P.RETURN_VAL, P.ST_NAME, P.ST_NUM, P.TAXDISTRIC
	FROM [WINGAP].AY2021.DBO.PERSONAL  P 
	LEFT JOIN [WINGAP].AY2021.DBO.OWNER O ON O.OWNKEY = P.OWNKEY 
	) wg ON LEFT(WG.LASTNAME,24)=G.OWNER_NAME AND WG.TAXDISTRIC=G.TAXDISTRIC AND CONVERT(INT,G.ST_VALUE1 )
			+ CONVERT(INT,G.ST_VALUE2 )
			+ CONVERT(INT,G.ST_VALUE3 )
			+ CONVERT(INT,G.ST_VALUE4 )
			+ CONVERT(INT,G.ST_VALUE5 )
			+ CONVERT(INT,G.ST_VALUE6 )
			+ CONVERT(INT,G.ST_VALUE7 )
			+ CONVERT(INT,G.ST_VALUE8 )
			+ CONVERT(INT,G.ST_VALUE9 )
			+ CONVERT(INT,G.ST_VALUE10) = WG.CURR_VAL

	 where g.bill_year=2021 and RIGHT(G.ST_CODE1,1) BETWEEN 'A' AND 'Z' --AND G.PREV_VAL=WG.PREV_VAL AND G.RETURN_VAL=WG.RETURN_VAL
	 AND WG.PERSKEY = 400 --IS NULL
/*
	and wg.perskey is null

SELECT * FROM MCDUFFIE_GSI.DBO.PARCEL WHERE BILL_YEAR=2012 AND RIGHT(ST_CODE1,1) BETWEEN 'A' AND 'Z' --2020 ROWS

select * from [wingap].ay2022.dbo.personal where curr_val > 0
	and ownkey in (select ownkey from [wingap].ay2022.dbo.personal group by ownkey having sum(curr_val) > 7500)

SELECT * FROM MCDUFFIE_GSI.DBO.PARCEL WHERE BILL_YEAR=2022 AND BILL_NO=13418
*/