Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL 2008 R2 Query count

Posted on 2013-06-17
3
Medium Priority
?
347 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 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