I don't know how exactly MS SQL behaves, but here is an equivalen in MySQL. Try to modify this to your needs:
select substring(zip, 1, 3) as ZIP, sum(AvailNums) as SUM
from AvailHomeZips group by ZIP;
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
I had tried the query pasted by me in my previous post on MySQL so I don't know what went wrong when the same was ported to MS SQL.
Try this:
select substring(zip, 1, 3) as Z, sum(AvailNums) as SUM from AvailHomeZips group by Z;
I guess MS SQL doesn't take into consideration the case hence the results. Post if it works or not.
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
If what you say is true, then try out this one:
select substring(zip, 1, 3), sum(AvailNums) from AvailHomeZips group by substring(zip, 1, 3);
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
Glad it worked out for you, though I must go out to say that MS SQL sucks if it can't even allow a alias to be used with the group-by clause which is so common a thing with present databases. So much for the Enterprise level database... ;-)
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733