The query looks like this
Select ID, TYPE, VALUE From myTable Where filtercondition = 1
ID TYPE VALUE
1 type1 12
1 type2 15
2 type1 16
2 type2 19
Each ID will have the same number of types and each type for each ID might have a different value. So if there are only two types then each ID will have two types. Now I want to write the query in such a way that it returns
ID TYPE1 TYPE2 VALUE1 VALUE2
1 type1 type2 12 15
2 type1 type2 16 19
Type1, Type2, Value1, and Value2 are all dynamic. Can someone help me please. Thank you.
I've done something like this, but not in SQL. What I do is build a datatable from my select results, populate it, and then return that to my caller. It works something like;
Get Results
Loope through results to get my columns (In my case there may not be a value for every type.)
Build datatable
Loop through results again, populating datatable.
Return datatable
No comments:
Post a Comment