Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Aggregating Data and Pivot without MAX

$
0
0

I'd like to perform a pivot operation based upon aggregation of data - but wish to capture the the data without the MAX clause, and instead concatenate the subvalues with an asterisk between them.

Here is my data:

DataTable

Id            AggregateDescription            SubDescription        Value

1000       Age                                         Age1                       24

1000       Age                                        Age2                       38

1000       Anesth                                    Anesth1                  ABC

1002       Anesth                                    Anesth1                  XYZ

1004       Anesth                                    Anesth1                  XYZ

1004       Anesth                                    Anesth2                  ABC

1005       Anesth                                    Anesth2                  WXY

1007       Age                                         Age2                       18

1008       Age                                         Age1                       27

1008       Age                                         Age2                       25

And here is the end result which I would like to accomplish

End Pivot Result

Id                           Age                         Anesth

1000                      24*38                     ABC

1002                      NULL                      XYZ

1004                      NULL                      XYZ*ABC

1005                      NULL                      WXY

1007                       18                           NULL

1008                       27*25                     NULL


John




Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>