Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 19th, 2007, 09:26 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default display count results and image in webpage

I am trying to count 5 categories, which will be based on the errorcode that has the most values. (eg errorcode1 was chosen 10 times, errocode2 was chosen 3 times all for category1, then the image in the cell next to category 1 should be red, because errorcode1 contained the most values for that category.

eg of how the webpage looks:
(5 categories, 5 errorcodes, 3 images for colorcode)

Ticket_view
Category 1 --> errorcode1(10) red
Category 2 --> errorcode2 (6) yellow
Category 3 --> errorcode3 (5) yellow
Category 4 --> errorcode4 (3) green
Category 5 --> errorcode5 (1) green

Color_code.dbo
legend:
green - 0-3 errors
yellow - 4-6 errors
red - 7+ errors

"SELECT category, COUNT(errorcode) AS id_number FROM ticket_view GROUP BY category"


  #2 (permalink)  
Old April 19th, 2007, 09:42 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Try this:

SELECT
CASE
WHEN Count(e1.ErrorCode) <= 3 Then Green
WHEN Count(e1.ErrorCode) > 3 AND Count(e1.ErrorCode) <= 6 Then Yellow
WHEN Count(e1.ErrorCode) > 6 Then Red
END as [Category 1],
CASE
WHEN Count(e2.ErrorCode) <= 3 Then Green
WHEN Count(e2.ErrorCode) > 3 AND Count(e2.ErrorCode) <= 6 Then Yellow
WHEN Count(e2.ErrorCode) > 6 Then Red
END as [Category 2]

FROM ticket_view e1
Left Join ticket_view e2 on e2.category = 'Category 2'
WHERE e1.category = 'Category 1'

Obviously you would wnat to join 3 more times to get the last 3 categories but you get the idea. The column name will be your category and the value of that column will be a color.

HTH.



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
  #3 (permalink)  
Old April 19th, 2007, 09:44 AM
Authorized User
 
Join Date: Aug 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you for your very fast help, i will try that right now.



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to count the number of access the webpage ? khb3283 ASP.NET 2.0 Basics 2 October 2nd, 2008 09:08 PM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
Display icon on a webpage rroohhiitt C# 3 February 24th, 2006 08:12 PM
display a pdf in a webpage crmpicco Classic ASP Basics 3 February 8th, 2005 09:59 AM
how to count the database search results of record gilgalbiblewheel Classic ASP Databases 2 July 31st, 2004 10:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.