I don't know how to word my question very well, so I will start with the data being returned:
prop_id | assessed_value | sale_id
35004 | 401200 | 1920831
35005 | 40500 | 1920831
35023 | 11300 | 1920831
34380 | 139100 | 1915846
127959 | 286400 | 1915882
I would like it to return:
prop_id | assessed_value | sale_id
35004, 35005, 35023 | 453000(Sum of the 3 parcels) | 1920831
34380 | 139100 | 1915846
127959 | 286400 | 1915882
So my main goal is to combine all the parcels on the sale_id field into a string, but only when a sale id has multiple prop_id, and then sum up the assessed value of all those. This is the query I am using to get the first set of data...
select
pv1.[prop_id],
pv1.[assessed_val],
ld1.[sale_id]
from dbo.land_detail as ld1
join dbo.property_val as pv1 on
pv1.[prop_id] = ld1.[prop_id] and
pv1.[prop_val_yr] = ld1.[prop_val_yr] and
pv1.[sup_num] = ld1.[sup_num]
left join dbo.sale as sale1 on
sale1.[chg_of_owner_id] = ld1.[sale_id]
where
pv1.[prop_inactive_dt] is null
order by sale_id, prop_id
prop_id is of data type INT
assessed_val is of data type numeric(14,0)
sale_id is of data type INT