I need to write a query that pulls out Zip codes by the first three characters, so I started with this:
SELECT SUBSTRING(Zip, 1, 3) FROM AvailHomeZips AS tZip
But I would also like to query out the zips by those substrings I pulled out, so that would be like this:
SELECT Zip From AvailHomeZips WHERE Zip LIKE @Zip + "%"
And I need the result to be unique, and also I would like to sum all of the values that are in a column called [AvailNums] which belong to zip codes that have similar beginnings.
In other words if there are four zip codes like so:
I would like the resultset to look like this: