|
Hello, 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.
(comments are locked)
|
|
You can use the PIVOT operator for this. Here you have an example for your task:
For more inforamtion look on MSDN
(comments are locked)
|
|
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/
(comments are locked)
|

