[UPHPU] OT: SQL question (MSSQL)
jmul.php at gmail.com
Wed Sep 6 19:59:18 MDT 2006
I have a SQL question. Please let me know if it is too far off topic and
I'll take this question elsewhere. I have to work with MSSQL but I think I
might be able to translate, if I have to, your suggestions based on your
knowledge of other rdbms's to make it work with MSSQL. I'm looking around
for an MSSQL mailing group to join that doesn't dive too far into .Net
I asked this question on the IRC channel but I'm still having a problem. I'm
trying to run a query that will return a charge_code and a count of how many
times this charge code was used. I'm also getting other data back but my
question has to do with the charge code and the count.
I've rearranged the code and tried all the ideas I could think of and I'm
still not getting the desired result. I want all 6300+ charge codes listed
in my result whether or not they were used. If they weren't used I want a
zero in the count column. What is happening is every single record contains
the total number of all the charge codes used in the time frame specified.
Example of what I'm getting…
Example of what I'd like to get…
Would I need a subquery with some sort of loop that adds up the count? If
so, I've never done loops in SQL. Are there any good web references? (Books
Online isn't helping me any) If using a loop is too complicated for this
problem, is there another (better) way to approach this?
More information about the UPHPU