troubleshooting Question

SQL: Counting the number of records

Avatar of John Ellis
John Ellis asked on
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008SQL
1 Comment1 Solution376 ViewsLast Modified:

I'm surprised that this is harder than I thought it would be.  All I want it for T-SQL to tell me the number of records, for a date range.  The following is my query:

from HRI..SOP30200
where HRI..SOP30200.DOCDATE BETWEEN '2016-02-01' AND '2016-02-29' AND HRI..SOP30200.SOPTYPE = '3'

The query says "tell me the invoice number and its date, where the date range is 02/01/2016 through 02/29/2016.

I tried using select COUNT(), but all this did was give me over a thousand records with the number "1" in each record.

Wow!  I just want to know how many invoices are returned by this query--plain and simple.  How do I do that?


Éric Moreau
Senior .Net Consultant
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
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 1 Comment.
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