Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to get column count?

Posted on 2011-09-20
2
Medium Priority
?
255 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
2 Comments
 
LVL 9

Accepted Solution

by:
sshah254 earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

810 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