Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Grouping

Author  Topic 

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2011-12-12 : 10:55:00
I have a Query that I am grouping by TOP 100 TIN and Practice Name. The results are great, but I want to add the columns with phone, fax, emails, etc, but I don't want it to change the number count of this. How can I do that? I am new to this type of reporting. Thanks

SELECT TOP (100) TIN,ProviderOffice,SUM(TOTALCHARGES) AS Total_Charges, SUM(ALLOWEDCHARGES) AS Allowed_Charges, SUM(SAVINGS) AS Total_Savings,
COUNT(DISTINCT claimnumber1) AS claim_Count
FROM vw_podiatry
WHERE (STATEMENTFROMDATE >= '01/01/2011') AND (STATEMENTFROMDATE <= '12/01/2011') AND
State = 'PA' and SpecialtyDescription = 'podiatry'
GROUP BY TIN,ProviderOffice
ORDER BY Total_Charges DESC

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-12 : 11:00:50
sorry your description wont make any sense to anybody who doesnt know the system. For example how do you think somebody will be able to get(guess) answers to the below questions?
1. How are columns phone,fax,etc stored in table? is it in same table or related table?
2. is it stored as columns itself or as rows? will it always have a value?
3. when you say you cant change number count what do you mean by that? if there are multiple rows storing different phone,fax,emails etc how would you return a single row? what shuld be the rule?

so in view of all these, best thing would be to post sample data and then explain what output you're expecting as given in below link

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sunnyleoneo
Starting Member

19 Posts

Posted - 2011-12-12 : 12:09:00
Please let us know table structure where phone, fax, emails, etc are stored. and also sample data will help a lot.

Only after this we can help you.

Go to Top of Page
   

- Advertisement -