troubleshooting Question

select Sum foreach custmoer

Avatar of Tech_Men
Tech_MenFlag for Israel asked on
Microsoft SQL Server 2005
6 Comments1 Solution208 ViewsLast Modified:
hi there
i have this code :

the resualt that i get for this code is row for each customer but the problem that i dont get total sum for eash custNum
i am geting 2 and 3 rows i need to get only 1 row Sum for each 1

this is the resualt that i geting :

total   CustName  SalDateEnd  CustNum
-----------------------------------------------------
2500    keter         31/07/2008      1
4640    gal             31/07/2008     3
222      Keter         31/07/2008     1
1000    gal            31/07/2008      3

i need to get only 1 sum for exsample :
--------------------------------------------------
2722   Keter       31/07/2008      1
5640   gal          31/07/2008       3

how can i fix my code ?
thanks ...







SELECT        SUM((((((((Sahar.RegHours * 1 + Sahar.Hour120 * 1.2) + Sahar.Hour125 * 1.25) + Sahar.Hour140 * 1.4) + Sahar.Hour150 * 1.5) + Sahar.Hour175 * 1.75) 
                         + Sahar.Hour200 * 2.0) + Sahar.Hour225 * 2.25) 
                         * Sahar.MoneyForHour + Sahar.TasNsiot + Sahar.Globaly + Sahar.HefrshySahar + Sahar.Manak - Sahar.HiovMils - Sahar.HiovBigod - Sahar.HiovHanala) 
                         AS total, Customers.CustName, Sahar.SalDateStart, Sahar.SalDateEnd, COUNT(*) AS Expr1, Customers.CustAddres, Customers.CustNum, 
                         Customers.CustCity
FROM            Sahar INNER JOIN
                         Customers ON Sahar.CustNum = Customers.CustNum
WHERE        (Sahar.SalDateEnd >= '07/01/08') AND (Sahar.SalDateEnd <= '07/31/08')
GROUP BY Customers.CustName, Sahar.SalDateStart, Sahar.SalDateEnd, Customers.CustAddres, Customers.CustNum, Customers.CustCity
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros