Solved

How to get column count?

Posted on 2011-09-20
2
239 Views
Last Modified: 2012-05-12
I would like to know which tickets are still open (those with Open=1 as last entry).  TicketNum is used to track added entries for a still open ticket.  TicketNum entries are just increments of the previous entry for the TicketTypeId.  Often, the same TicketType is used.  Once a ticket is closed and another open, the new ticket starts with TicketNum=1 and the process starts all over.

In the code example, only employeeIds 5 (Id=7) and 6 (Id=12) have open tickets.

 
Id   empId  ticketNum   TicketTypeId   Open   DateCreated
1       2           1     6              0
2       2           1     8              0
3       2           1     9              1
4       2           2     9              0
5       5           1     6              0
6       5           1     9              1
7       5           2     9              1
8       6           1     9              1
9       6           2     9              0
10      6           1     9              1
11      6           2     9              1
12      6           3     9              1

Open in new window

0
Comment
Question by:brettr
[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 Comments
 
LVL 9

Accepted Solution

by:
sshah254 earned 500 total points
ID: 36568667
Select count(*) from table a inner join
(select max(Id), ticketNum as maxid from table group by ticketNum) b
on a.id = b.id and a.ticketNum = b.ticketNum
where a.Open = 1

SS
0
 

Author Comment

by:brettr
ID: 36568725
Thanks but getting a few errors.

No column was specified for column 1 of 'b'

Invalid column name 'id'

Where you have a.id = b.id, b.id is not valid correct?
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 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