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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-01-20 : 08:40:39
|
| davrok writes "I have the following sql:SELECT CASE WHEN (GROUPING(dbo.products.product_id) = 1 and GROUPING(dbo.terminal_stores.ters_CONTINENT_ID) = 1) THEN 9999999 ELSE dbo.products.product_id END AS product_ID, sum(dbo.stock_contract.kilos) as kilos,max(dbo.continents.continent) as continent, max(dbo.products.product_name) as product_nameFROM dbo.STOCK_CONTRACT INNER JOINdbo.TERMINAL_CLIENTS_MAPPING ON dbo.STOCK_CONTRACT.TRADER_ID = dbo.TERMINAL_CLIENTS_MAPPING.TERMINAL_TRADER_ID AND dbo.STOCK_CONTRACT.TERMINAL_HO_GUID = dbo.TERMINAL_CLIENTS_MAPPING.TERMINAL_HEAD_OFFICE_GUID INNER JOINdbo.TERMINAL_STORES ON dbo.STOCK_CONTRACT.TERMINAL_ID = dbo.TERMINAL_STORES.TERMINAL_STORE_REF_ID AND dbo.STOCK_CONTRACT.TERMINAL_HO_GUID = dbo.TERMINAL_STORES.TERMINAL_HO_GUID INNER JOINdbo.TERMINAL_PRODUCTS_MAPPING ON dbo.STOCK_CONTRACT.PRODUCT_ID = dbo.TERMINAL_PRODUCTS_MAPPING.TERMINAL_PRODUCT_CODE AND dbo.STOCK_CONTRACT.TERMINAL_HO_GUID = dbo.TERMINAL_PRODUCTS_MAPPING.TERMINAL_HEAD_OFFICE_GUID INNER JOINdbo.PRODUCTS ON dbo.TERMINAL_PRODUCTS_MAPPING.PRODUCT_ID = dbo.PRODUCTS.PRODUCT_ID INNER JOINdbo.CONTINENTS ON dbo.TERMINAL_STORES.TERS_CONTINENT_ID = dbo.CONTINENTS.CONTINENT_IDWHERE (dbo.TERMINAL_CLIENTS_MAPPING.CLIENT_HEAD_OFFICE_GUID = '{DDEA952A-8E59-4353-9965-BD555E5B6579}')GROUP BY dbo.terminal_stores.ters_CONTINENT_ID, dbo.products.product_id WITH ROLLUPwhich produces the following results:prodid kilos continent product320 10 Europe Apples320 12 Europe Apples346 30 Europe Bananas1711 5 Europe GrapesNULL 57 Europe Apples320 30 Asia Apples346 15 Asia Bananas346 15 Asia BananasNULL 60 Asia Bananas9999999 117 Asia BananasAs you can see the two NULL columns are the sum of ALL productsand 999999 column is the sum of both NULL column totals.What i am trying to achieve as results is this, which is breakdown of the products by continent with a total of that product after each:Continent Product kilosAsia Apples 30Europe Apples 22Total 52Asia Bananas 30Europe Bananas 30Total 60Europe Grapes 5Total 5Thanks in advance for any help...." |
|
|
blindman
Master Smack Fu Yak Hacker
2365 Posts |
Posted - 2006-01-20 : 10:44:27
|
| You are trying to do reporting in SQL Server. SQL Server is a data server, not a reporting tool. Use Crystal Reports, MS Access, Active Reports, or some other tool that is appropriate for this. |
 |
|
|
|
|
|