Solved

SQL 2008 R2 Query count

Posted on 2013-06-17
3
334 Views
Last Modified: 2013-06-17
Hello

I have a the following count Query

Select COUNT (*) as 'Closed' from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where HDTicket_IsClosed = '1' And HDTicket_Closed >= Dateadd(WW, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate' 

Select count (*) as 'Opened' from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where  HDTicket_Created >= Dateadd(WW, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate'

Select count (*) as 'Idle' from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where HDTicket_IsClosed = '0' And HDTicket_Modified < Dateadd(ww, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate'
 
Select count (*) as 'Modified' from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where HDTicket_IsClosed = '0' And HDTicket_Modified >= Dateadd(ww, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate'

Open in new window


Currently this query outputs 4 different tables, I would like to have them displayed in one table like this:
 
Closed, Opened,  Idle, Modified
13,10,15,1

Thanks in advanced.
0
Comment
Question by:macomsupport
  • 2
3 Comments
 
LVL 6

Expert Comment

by:BurundiLapp
ID: 39253538
--

Sorry I've misread your question, hang on I'll post code that should do what you are after.
0
 
LVL 6

Accepted Solution

by:
BurundiLapp earned 500 total points
ID: 39253553
Give this a try:

SELECT 
(SELECT COUNT (*) from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where HDTicket_IsClosed = '1' And HDTicket_Closed >= Dateadd(WW, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate') as Closed, 

(Select count (*) from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where  HDTicket_Created >= Dateadd(WW, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate') as Opened,

(Select count (*) from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where HDTicket_IsClosed = '0' And HDTicket_Modified < Dateadd(ww, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate') as Idle,

(Select count (*) from [macom].[dbo].[dt_HDTicket] Join [macom].[dbo].[dt_HDStatus] on HDTicket_HDStatus_id=HDStatus_ID 
where HDTicket_IsClosed = '0' And HDTicket_Modified >= Dateadd(ww, -1, getdate()) and HDStatus_HDProject_id = '7' and HDStatus_Name <> 'Duplicate') as Modified

Open in new window

0
 

Author Closing Comment

by:macomsupport
ID: 39254069
Perfect. Thanks!
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now