I have one table Person:
And I have its child table Profile:
And I want to get data from these two tables in onw row like this:
I would like to have strongly types in my DB layer (C#) and using LINQ (when programming) so it means when I add some new Key, Value pair in Profile table I would like to do minimal modifications in DB and C# if possible. Actually I am trying to get some best practises in this case.
asked Apr 15 '10 at 06:19 AM in Default
You can use the PIVOT operator for this.
Here you have an example for your task:
For more inforamtion look on MSDN
answered Apr 15 '10 at 07:34 AM
First, it would be a big help to everyone if you posted data in a readily consumable format. That includes table creation statments. Pavel took the time to do that and I'll do it as well this time just to show another method. It almost guarantees that you'll get a coded/tested answer and it identifies the data types we need to work with. Here's the test setup code...
Here's another way to do the same thing Pavel did for an answer... it's called a "CROSS TAB" and is usually just a bit faster than a pivot...
Please see the following article for why... http://www.sqlservercentral.com/articles/T-SQL/63681/
answered Apr 19 '10 at 02:32 AM