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
 SQL Server Development (2000)
 Save me from a cursor!

Author  Topic 

inrsence
Starting Member

48 Posts

Posted - 2001-08-30 : 13:26:06
Hello,

OK.. I thought I had seen a way to do this somewhere, but I can't find it. Here is my problem.

I've got a table storing data. It looks like this:

Region varchar(20)
Score int
Attempts int

I want to generate a table that looks like this:

Region varchar(20)
Total int -- The total tests for the region
Lazy int -- The total tests that made 0 attempts

So I was writing this:

CREATE TABLE #Results(Region varchar(20), Total int, Lazy int)

INSERT INTO #Results(Region,Total)
SELECT Region,Count(*)
FROM table
GROUP BY Region

Now I want to update to get the last set of values.. but I'm not sure how to get those. I know that the query that would return the values for Lazy looks like this:

SELECT Region,Count(*)
FROM table
GROUP BY Region
HAVING SUM(Attempts) = 0

How do I combine this with what I have above to perform the update.. I know I can get it with a cursor.. but I would really like to avoid that.

Anyone got some helpful advice?

Thanks in advance,
Greg



   

- Advertisement -