troubleshooting Question

Counting records in SQL query

Avatar of nkewney
nkewneyFlag for United Kingdom of Great Britain and Northern Ireland asked on
DatabasesMicrosoft SQL Server 2008
5 Comments1 Solution195 ViewsLast Modified:
Dear Experts,

I'm having a few issues counting the total number of records returned for this query.

I'm unable to change the query as it's generated by a system, but would like to be able to count the number of records returned as a COUNT() or otherwise.

I have tried and failed to count the correct number of records (3) returned by this query.

Could anybody point me in the right direction?

Thanks

Nick
SELECT DISTINCT OutletProductCustomFieldValues.Outlet_ID
FROM         AccountOutlets RIGHT OUTER JOIN
                      OutletProductCustomFieldValues_Historic ON AccountOutlets.Outlet_ID = OutletProductCustomFieldValues_Historic.Outlet_ID RIGHT OUTER JOIN
                      OutletProductCustomFieldValues INNER JOIN
                      CustomFields ON OutletProductCustomFieldValues.CustomField_ID = CustomFields.CustomField_ID ON 
                      OutletProductCustomFieldValues_Historic.CustomField_ID = OutletProductCustomFieldValues.CustomField_ID AND 
                      OutletProductCustomFieldValues_Historic.Product_ID = OutletProductCustomFieldValues.Product_ID
GROUP BY OutletProductCustomFieldValues.Outlet_ID, CustomFields.Company_ID, OutletProductCustomFieldValues_Historic.Modified, 
                      AccountOutlets.Account_ID, OutletProductCustomFieldValues.Product_ID, 
                      OutletProductCustomFieldValues_Historic.OutletCustomFieldValue_Value
HAVING      (CustomFields.Company_ID = 102) AND (OutletProductCustomFieldValues_Historic.Modified BETWEEN CONVERT(DATETIME, '11/03/2007', 102) AND 
                      CONVERT(DATETIME, '11/04/2009', 102)) AND (OutletProductCustomFieldValues.Product_ID = 51) AND (0 = 0) AND (AccountOutlets.Account_ID = 156) 
                      AND (OutletProductCustomFieldValues_Historic.OutletCustomFieldValue_Value = '160')
ASKER CERTIFIED SOLUTION
Arthur_Wood

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
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 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