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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 COMPUTE

Author  Topic 

cjonline
Yak Posting Veteran

55 Posts

Posted - 2005-05-18 : 07:17:53
Hi,

I am taking a count of a file "Answer" (below) for each row, however, I would like to total the count of answer like a grand total. I started to use the Compute function which does exactly what I want except I am having problems returning the data to a recordset in ASP. Anyone help me perform this task. thanks.

SQL QUERY-
select QuestionNo,test=Count(Answer), Answer from SurveyA where surveyno = 7 and questionno=2 group by Answer,QuestionNo compute sum(count(answer))

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-05-18 : 07:28:36
Try ROLLUP or CUBE, they are documented in Books Online and will return their summaries in the regular recordset. I've used them both for ASP pages and they work extremely well.
Go to Top of Page

cjonline
Yak Posting Veteran

55 Posts

Posted - 2005-05-18 : 09:11:10
When I try to use the Rollup or cube function on the Query analyser it says "not a recognized function name".

I'm using sQl server 2000.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-05-18 : 12:59:25
The syntax is as follows:

select QuestionNo,test=Count(Answer), Answer from SurveyA where surveyno = 7 and questionno=2 group by Answer,QuestionNo with rollup

You'll get an extra summary row for each of the the two groups, plus an additional row summarizing the entire set. Use the GROUPING() function to identify summary rows. There's an example in Books Online under "CUBE" and "ROLLUP".
Go to Top of Page
   

- Advertisement -