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 2008 Forums
 Transact-SQL (2008)
 Help building query

Author  Topic 

Pete_N
Posting Yak Master

181 Posts

Posted - 2011-06-22 : 15:22:42
SELECT [Licence]
,[CompanyName]
,[Status]
,[ServiceID]
FROM [DB1].[dbo].[clients]
( status = Live, Test, Install, Ordered, Cancelled )

SELECT [ServiceID]
,[Name]
FROM [DB1].[dbo].[Service]

How can i get the following result ;

Live Test Install Ordered Cancelled Suspended
Service1Name 55 0 9 0 0 0 Service2Name 7 8 0 0 0 0

McBeef
Starting Member

14 Posts

Posted - 2011-06-22 : 18:42:45
Do you want a count of each status type for each company? If so I would start by creating a view that has a GROUP BY for Licence, Name, Status and a 4th column set to Count. Name will need to be brought in by an INNER JOIN. It won't be formatted as you specified, with each status as a column but it will have the same data that you want.
Go to Top of Page
   

- Advertisement -