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)
 Trying to build Count query

Author  Topic 

roer
Starting Member

2 Posts

Posted - 2008-04-22 : 09:54:09
I have a table which tracks changes by user, department and date. I want to construct a query which returns two numbers, the first is all the changes by department on a certain date. The second is all changes by user on the same date. I know that the queries seperately will look like,

SELECT COUNT(User) As NumberByUser
FROM Table
WHERE (Date = 'DateGoesHere') AND (User= 'UserGoesHere')
GROUP BY User

SELECT COUNT(Department) As NumberByDepartment
FROM Table
WHERE (Date = 'DateGoesHere') AND (Department = 'DepartmentGoesHere')
GROUP BY Department

But how do I go about linking the two in the same query? Any help would be appreciated, thanks!

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-22 : 10:02:10
{query 1}
UNION ALL
{query 2}



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

roer
Starting Member

2 Posts

Posted - 2008-04-22 : 10:05:11
Worked perfectly, thanks!
Go to Top of Page
   

- Advertisement -