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 |
|
handora
Starting Member
2 Posts |
Posted - 2006-04-19 : 11:19:06
|
| Hello,Using SQL Server 2000 Query Analyzer, I am trying to display something like the below example with a reportCategoryCode = Q Submissions = 20340 10320 5330 4ODO 1CategoryCode = B Submissions = 15620 8640 4330 2ODO 1 The codes under the CategoryCode refers to DescriptionCodes and numbers the total number of submissions for those DescriptionCodes under the specific CategoryCode. I have no problem to get the results in two separate stored procedures, considering that CategoryCode is passed to display the DescriptionCodes. Can it be done in one script in the same format without using a cursor? Thanks for your time,Handora |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-04-19 : 11:24:55
|
| Can u provide with ur table(s) structure, some sample data and expected results?Its hard to findDescriptionCodes ?Submissions ?The lists of data (that u have given)?One thing is sure, that u'd do it without a cursorSrinika |
 |
|
|
handora
Starting Member
2 Posts |
Posted - 2006-04-19 : 11:49:45
|
| I know. I am sorry for sending not enough info. There are a few tables involved and the report is more complex than I am showing. I tried to eliminate all and just give you my main problem. OK. I'll try this way. Let's say I have the following table with the test data below.select TicketID, SeverityCode, CategoryCode, DescriptionCode from Tickets 1 S B 0102 2 H 6103 3 N 84010 S B 01011 S B 01012 S B 01013 S B 01050 3 H 61051 3 H 61059 S B 01061 S B 01062 S B 01063 S B 61064 S B 01065 1 B 610when I try display the first part of the report, I would need a query like below:SELECT CategoryCode, count(CategoryCode) as 'Submissions'FROM Tickets GROUP BY CategoryCode ORDER BY Submissions descand will get the resultsCategoryCode SubmissionsB 11H 3N 1for the second part I'll need something as the following:DECLARE @CategoryCode varchar(10)select @CategoryCode = 'B'SELECT DescriptionCode, count(DescriptionCode) as 'Submissions'FROM Tickets WHERE CategoryCode = @CategoryCodeGROUP BY DescriptionCode ORDER BY Submissions descand I'll get the resultsDescriptionCode Submissions010 9610 2I want to accomplish in one shot to displayCategoryCode = B Submissions = 11010 9610 2CategoryCode = H Submissions = 3610 3CategoryCode = N Submissions = 1840 1Is it possible? |
 |
|
|
|
|
|
|
|