Solved

How to get column count?

Posted on 2011-09-20
2
217 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 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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