I have 3 tables in database shown below. And I want to make a report just like shown link below. How can I do it with datagrid or datalist? Which one is the best chois? I have tried to do it for a week.
COMPANY: ID_COMPANY, COMPANY_NAME
PRODUCT: ID_PRODUCT, PRODUCT_NAME
PRODUCT_SALE: ID_COMPANY, ID_PRODUCT, SALE_COUNT
Updated :
I could do it, with your helps. However Now I have a small problem too.
When I write query with pivot, products' name become column header. if a product name's length is bigger than 30 character, Oracle don't accept it as a column header. So I have croped and make the product names 30 character to solve this problem. After that a problem occured too.
When I crop product name as 30 character, some products become same name and "ORA-00918: column ambiguously defined" error message occured.
In this case what can be done?
Use a standard sql query (pivots are expensive in terms of performance) and create a custom pivot function in your server side code. Here are a couple of examples.
Use nested Repeaters Control. The outer repeater will repeat Companies and the inner will repeat Products.
Looks like a crosstab report to me. You have 2 options to go about this
Following will work if product numbers are static:
Manage the product sales according to the product id in your query using inline queries.
What version of SQL are you running? Using PIVOT might be a quick way to get the data into the form you want, and then you can use the generic DataGrid to just display the data in it's (almost) "raw" form - that is, the way the data is presented by the SQL server. You could then think of the DataGrid more like a spreadsheet than representative of a data table as found in a database.
Here's a good starter document for how to use PIVOT to represent the data in the form you're after:
Of course, I think this might only be available in SQL 2005... so if you're running an older version this may be no help.
Updated :
On Oracle 10g you're going to need the MODEL extension, it's not a world different than PIVOT in SQL but obviously Oracle 10g does things its own way: Check this link
On Oracle 10g you're going to need the MODEL extension, it's not a world different than PIVOT in SQL but obviously Oracle 10g does things its own way:
http://technology.amis.nl/blog/300/pivoting-in-sql-using-the-10g-model-clause