Re: Can I do this using SQL?

From: Tony Rogerson <tonyrogerson_at_sqlserverfaq.com>
Date: Fri, 10 Feb 2006 08:25:49 -0000
Message-ID: <dshilm$6p0$1$8302bc10_at_news.demon.co.uk>


What, CELKO writing a cursor?

I'm shocked!

Is this one of the 'many' situations where properitary features come in to play while the standards committe catch up with stuff industry really needs.

In SQL Server you would write...

SELECT TOP 10 branch_name,

                SUM(acct_balance) AS activity_tot,
                COUNT(cust_id) AS cust_tally
FROM BranchActivity
GROUP BY branch_name
ORDER BY activity_tot;

Which gives you a result set you can use, whereas with standard SQL you would have to embed the SQL in the application (and not use stored procedures).

-- 
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials


"-CELKO-" <jcelko212_at_earthlink.net> wrote in message 
news:1139540128.434166.136380_at_g44g2000cwa.googlegroups.com...

>I assume that a big balance is how you rate the branches.
>
> DECLARE BestTenBranches CURSOR FOR
> SELECT branch_name, SUM(acct_balance) AS activity_tot, COUNT(cust_id)
> AS cust_tally
> FROM BranchActivity
> GROUP BY branch_name
> ORDER BY activity_tot;
>
> The TOP n operator is a SQL Server extension, but you can do this with
> a cursor in Standard SQL, as shown.
>
Received on Fri Feb 10 2006 - 09:25:49 CET

Original text of this message