troubleshooting Question

Stored Procedure not giving correct data.

Avatar of dlavar
dlavar asked on
Microsoft SQL Server 2008
5 Comments2 Solutions203 ViewsLast Modified:
The query below is resulting in the following data which is not what i want..

vchRecordID       vchManufacturer              vchCertificationType    Number of Brands  Total Amount Owed
T-110057      COMMONWEALTH BRANDS, INC      Initial      6      6000


what it really should be populating is 3 for number of distinct brands and 3000 for total amount owed.

What wrong with my query?  I know its populating the following because in the tblCLBrandFamily the recordid is in there 3 different times which is possible. I've tried adding distinct to the query but it doesn't work. how can i get it to work?
SELECT  t.vchRecordID, t.vchManufacturer, a.vchCertificationType, 
    COUNT(b.vchBrandFamily)as 'Number of Brands', 'Total Amount Owed'=
        (Case
    when vchCertificationType = 'Initial' then '1000'
    when vchCertificationType = '3 Year Renewal' then '1000'
    when vchCertificationType ='Corrective Filing' then '0'
    end) * COUNT(b.vchBrandFamily)
    from tblCLTestLab t
    inner join tblCLApplicants a on t.vchManufacturer = a.vchManufacturer
    Inner join  tblCLBrandFamily b on t.vchRecordID = b.vchRecordID
    where t.vchRecordID = 'T-110057'
    group by t.vchRecordID, t.vchManufacturer,  a.vchCertificationType
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 5 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 2 Answers and 5 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