Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 COUNT entries between dates

Author  Topic 

Zath
Constraint Violating Yak Guru

298 Posts

Posted - 2011-06-15 : 12:35:45

This sql works fine but I need to also know how many times in the sql the A.RequestBy appears or the count of each distinct entry and also list it....


SELECT DISTINCT U.UserID, U.fname + ' ' + U.lname AS 'Requested By'
FROM Entries A
INNER JOIN UserInfo U ON U.UserID = A.RequestBy
WHERE A.requestdate BETWEEN '01/01/2011' AND '05/31/2011'


Been trying to find a way but need some input.

Thanks!

Zath

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-15 : 13:36:57
SELECT U.UserID, max(U.fname + ' ' + U.lname) AS [Requested By], count(*)
FROM Entries A
INNER JOIN UserInfo U ON U.UserID = A.RequestBy
WHERE A.requestdate BETWEEN '01/01/2011' AND '05/31/2011'
group by U.UserID

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -