Solved

SQL 2008 R2 Query count

Posted on 2013-06-17
3
336 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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