Under the my query.I select this way all job count by fullname.
SELECT COUNT(sy.FullName) [Count Job],
sy.FullName [FullName],
MIN(CAST(i.vrp_notificationdate AS DATE)) [Oldest Date]
FROM BusinessUnit AS b
INNER JOIN SystemUser AS sy
ON b.BusinessUnitId = sy.BusinessUnitId
INNER JOIN Incident AS i
ON i.OwnerId = sy.SystemUserId
GROUP BY f.sy.FullName
This query show this table
--------------------------------- Count Job FullName Oldest Date 10 a 2011-10-11 20 B 2011-10-11 55 C 2011-10-11 ---------------------------------
But i want to make under table for example.
-------------------------------------------------------------- Count Job FullName Oldest Date Open Job Close Job 10 A 2011-10-11 5 5 20 B 2011-10-11 13 7 55 C 2011-10-11 48 7 ------------------------------------------------------------
I have status of columnname on my Incident Table,if status code is 5 that the job is closed.when i used group by condition statuscode,then table is under .And i dont want show this showing table.
--------------------------------- Count Job FullName Oldest Date 10 a 2011-10-11 13 B 2011-10-11 48 C 2011-10-11 7 B 2011-10-11 7 C 2011-10-11 ---------------------------------
when i use union on my t-sql,i take this error “all queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.”
how to exactly solve this query.Any suggestion.
Thanks.
How about using CASE and SUM?