SQL: Counting the number of records

John Ellis
John Ellis used Ask the Experts™
on
Hello:

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:

select HRI..SOP30200.SOPNUMBE, HRI..SOP30200.DOCDATE
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?

Thanks!

John
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior .Net Consultant
Top Expert 2016
Commented:
replace the SELECT clause

select count(*)
 from HRI..SOP30200
 where HRI..SOP30200.DOCDATE BETWEEN '2016-02-01' AND '2016-02-29' AND HRI..SOP30200.SOPTYPE = '3'

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial