Here's my question:
I have a database structured like this:
|ID_Brand| Description
------------------------------
|1 | CoolBrandName
|2 | AlsoCoolBrandName
|... | ...
Linked to this table I created a File table like this
|ID_file | ID_BRAND | DESCRIPTION | FILECONTENT | ID_CATEGORY
-------------------------------------------------------------
|1 | 1 | File1 |0x0FF0A0B2..| 1
|2 | 1 | File2 |0x2F1A000C..| 2
|3 | 2 | File3 |0X5FB43002..| 1
|4 | 1 | File4 |0x93EEFD13..| 1
|... |... | ... |... | ...
Eventually the Category table, linked to the above table with the ID_CATEGORY association.
|ID_CATEGORY | DESCRIPTION
--------------------------
|1 | Category1
|2 | Category2
|3 | Category3
|4 | Category4
|... | ...
I need to show the data on these tables like a pivot table, grouped on the category. For example with the data above i need to output something like this:
|BrandName | Category1 | Category2 | Category3 | Category4
------------------------------------------------------------------
|CoolBrandName | File1 | File2 | *NULL* | *NULL*
|AlsoCoolBrandName | File3 | *NULL* | *NULL* | *NULL*
|CoolBrandName | File4 | *NULL* | *NULL* | *NULL*
The category table has a fixed number of rows.
I tried starting with the examples on http://msdn.microsoft.com/en-us/library/ms177410.aspx but with no luck.
I need to achieve this via SQL (I'm using sql server 2008 r2) or via Linq either.
Can anyone help me going through this?
I appreciate any suggestion.
Thanks in advance V.
File1
andFile4
are the same brand and belong to the same category. How then does one know which one should go on the same row withFile2
? – Andriy M Dec 21 '11 at 23:08File1
orFile4
, should go withFile2
. – Andriy M Dec 22 '11 at 8:31