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 |
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2008-08-06 : 09:25:48
|
| Hi, I have two tables which are joined by ZMproducts.productlocationid and ZMLocation.LocationId:- ZMProducts (with columns productid, productname, quantity, productlocationid productcategoryid, etc....)- ZMLocation (with colums locationid, locationname, locationprovinceid)- Each product has 1 productcategoryid which links to another table with categories- Each location has 1 locationprovinceid which links to another table with provincesNow I need to make an overview of products by category, and products by provinces and a combination of this.Now I already have a SP for every category GetProductsByCategoryIDAnd I already have a SP for every province GetProductsByProvinceIDBut I think this can be done better to make an overview like this:Category Number of products Quantitycat1 5 20cat2 2 100cat3 4 50TOTAL 11 170 And I must also split them for each provinceso:Province1Category Number of products Quantitycat1 1 10cat2 2 100Total 3 110Province2Category Number of products Quantitycat1 4 10cat3 4 50 Total 8 60 |
|
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2008-08-06 : 09:31:33
|
| Wouldn't this be called a Pivot query or something?Don't know much about it.has anyone got any clues for me...The secret to creativity is knowing how to hide your sources. (Einstein) |
 |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-06 : 09:48:51
|
| from the way you've shown your required result, it looks as though what you really want is to write a report with seperate groups / totals etc. this is not something to be done in t-sql. you can group it by province / category etc, but not split it out in the way you have shownwhat are you using for your front end?Em |
 |
|
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2008-08-06 : 09:58:24
|
| I'm building in visual basic . net.And I was indeed thinking of looping through some lists a couple of times and executing some SP's. But I am looking at a nice way of doing this. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-06 : 13:16:54
|
| You could return the data in the following formatProvince Category Number of products QuantityProvince1 cat1 1 10Province1 cat2 2 100Province1 null 3 110Province2 cat1 4 10Province2 cat3 4 50Province2 null 8 60and then use your front end app to format it in order you want. |
 |
|
|
|
|
|