Solved

How to get column count?

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now