Query Syntax Problem

I wrote a simple query that counts the the number of docments given a specific peroid in a sql database.  The query works.  It lists the document categories and then gives me a count for each one.  Please see below.  I am trying to expand the query to list the document categories but break down by user.  My current query gives me results such as the following.

Document1     3
Document2     7

I want the results to look like the following:

Mike Smith Document1 2
Bob Jenss  Document1  1
Mike Smith Document2 4
Bob Jenss Document2   3

The Column name is CreateUserID.  I assume I need another "group by", but I could be wrong. I cannot get the syntax correct.  I would greatly apperciate any help.

Select DocumentCategory, Count(*) As DocumentCount
from tblCsDocument
where EnterDate between Convert(datetime, '2014-01-01') and Convert(datetime, '2014-12-31')
group by DocumentCa

August 22nd, 2015 11:47am

Yes, just add the CreateUserID column to the SELECT and GROUP BY clauses.  Also, no need for the explicit CONVERT of the datetime literal if you a neutral datetime literal:

SELECT CreateUserID, DocumentCategory, Count(*) As DocumentCount
FROM dbo.tblCsDocument
WHERE EnterDate BETWEEN '20140101' AND '20141231'
GROUP BY CreateUserID, DocumentCategory;

Free Windows Admin Tool Kit Click here and download it now
August 22nd, 2015 12:11pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics