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 |
|
mason
Starting Member
11 Posts |
Posted - 2003-06-09 : 16:06:59
|
| Only other proc I'm having troubles with is one wherein I need to return the continents for the US, Mexico, Canada, France, Italy, and Australia) and the sum for the orders for each of thse continents. On top of this I will need to reference the Customer and Orders table for the above AND use a cursor for this proc.Help I'm completely stuck! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-06-09 : 16:12:39
|
| Well none of us here will give you a solution that involves a cursor since cursors shouldn't be used in almost all circumstances. If you would provide the DDL and sample data, we might be able to help you come up with a better solution.Tara |
 |
|
|
mason
Starting Member
11 Posts |
Posted - 2003-06-09 : 16:17:31
|
| Why would using a cursor in this example be bad? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-06-09 : 16:20:11
|
| Because cursors do not perform well. Set-based approaches are faster. If you do a forum search on cursors, you'll see many, many threads as to why they are so bad.Tara |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-06-09 : 21:46:45
|
Something like this should work:SELECT C.Continent, Count(*) AS Orders, Sum(O.SalesAmount) AS TotalFROM Countries C INNER JOIN Customers CS ON C.Country=CS.CountryINNER JOIN Orders O ON CS.CustomerID=O.CustomerIDWHERE C.Country IN('Australia', 'USA', 'Mexico', 'Canada', 'France', 'Italy')GROUP BY C.ContinentI'm sure your table structures differ, but that will give you the idea. As Tara suggested, if you post your actual DDL we can come up with a more specific solution, and no cursors needed. |
 |
|
|
|
|
|
|
|