Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
missshhhh
Starting Member
1 Post |
Posted - 2006-12-31 : 04:32:00
|
I have a table called Tickets and a column called Type. The values of Type are Fault, Request and Inquiry. My query is SELECT Count(*), Type FROM Tickets WHERE Type = "Fault" Group By Type. My problem is if there are no records in table Ticket that has a "Fault" type then no results will be displayed. I want that the query will display Fault 0. Thanks |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2006-12-31 : 04:50:20
|
[code]SET NOCOUNT ONCreate Table #types (type varchar(8))INSERT #t VALUES('Fault')INSERT #t VALUES('Request')INSERT #t VALUES('Inquiry')SELECT t.type, isNull(count(a.type), 0)FROM #types tLEFT JOIN tickets aOn a.type = t.typeWHERE t.type = 'Fault'GROUP BY t.typeDrop Table #types[/code] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|