Best way to concatenate column values in aggregate

Traceur

I have a table that looks like

srvc_dt     fclity_id  clmt_key rfrsh_dt    srvc_cd
2013-01-16  000167404   2       2013-01-31  01204
2013-01-16  000167404   2       2013-01-31  11112
2011-01-11  000167404   2488    2013-02-28  11113
2013-01-08  000167404   6070    2013-01-31  11113
2013-01-08  000167404   28371   2013-01-31  01202
2013-01-08  000167404   28371   2013-01-31  11107
2013-01-08  000167404   28371   2013-01-31  11112
2013-01-08  000167404   28371   2013-01-31  11117
2013-01-08  000167404   28371   2013-01-31  12101
2012-07-17  000167404   40571   2013-01-31  11113
2012-11-19  000167404   40571   2013-01-31  11113
2013-01-14  000167404   44189   2013-01-31  27211
2010-07-06  000167404   46396   2013-02-28  01202
2010-07-06  000167404   46396   2013-02-28  02142
2010-07-06  000167404   46396   2013-02-28  11107
2010-07-06  000167404   46396   2013-02-28  11112
2013-01-03  000167404   113264  2013-01-31  01204
2013-01-03  000167404   113264  2013-01-31  23323
2013-01-07  000167404   113390  2013-01-31  01202
2013-01-07  000167404   113390  2013-01-31  02142

and I would like to transform it into something like

srvc_dt     fclity_id  clmt_key rfrsh_dt      srvc_cd
2010-07-06  000167404   46396   2013-02-28    01202,02142,11107,11112
2011-01-11  000167404   2488    2013-02-28    11113
2012-07-17  000167404   40571   2013-01-31    11113
2012-11-19  000167404   40571   2013-01-31    11113
2013-01-03  000167404   113264  2013-01-31    01204,23323
2013-01-07  000167404   113390  2013-01-31    01202,02142
2013-01-08  000167404   6070    2013-01-31    11113
2013-01-08  000167404   28371   2013-01-31    01202,11107,11112,11117,12101
2013-01-14  000167404   44189   2013-01-31    27211
2013-01-16  000167404   2       2013-01-31    01204,11112

what would be the most performant (for > 100 000 000 rows) way to accomplish this in SQL SERVER 2012?

PIVOT? FOR XML PATH? dynamic case statements? something else?

EDIT: while Simulating group_concat MySQL function in Microsoft SQL Server 2005? does display 1 way to accomplish this, I'm looking for performance comparisons between different methods

Tim Lehner

Grouped Concatenation in SQL Server by Aaron Bertrand offers a good look at what you want.

I normally don't like link-only answers, but since you're looking for the performance comparison of various techniques, there's no reason to duplicate a huge article here.

I also agree with the comments which say you'll ultimately have to test these solutions on your system with your data anyway. If performance really matters, you'll have to measure for yourself.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Concatenate column values

From Dev

JPA concatenate STRING column values into a single value just like an aggregate function

From Dev

JPA concatenate STRING column values into a single value just like an aggregate function

From Dev

Best way to aggregate logging data

From Dev

concatenate column name and column values

From Dev

Shell script- best way to read column values and store to variable?

From Dev

Concatenate mysql column values in php

From Dev

Best way to switch values

From Dev

C: What is the best and fastest way to concatenate strings

From Dev

SQL Server: Best way to concatenate multiple columns?

From Dev

C: What is the best and fastest way to concatenate strings

From Dev

Column to aggregate values in another one

From Dev

Best way to aggregate a simple dict in Python

From Dev

Best way to aggregate a simple dict in Python

From Dev

What is the best way to index aggregate data on ElasticSearch

From Dev

Concatenate column values against another column group

From Dev

Concatenate column values in Pandas DataFrame with "NaN" values

From Dev

Concatenate characters of string values to the same column values

From Dev

Concatenate column values in Pandas DataFrame with "NaN" values

From Dev

Aggregate Pandas Column based on values in Column Range

From Dev

Mysql best way to increase a column?

From Java

Java compare values, best way

From Dev

Best way to add values to an object?

From Dev

Java compare values, best way

From Dev

Python Pandas: Join on unique column values and concatenate

From Dev

SQL Server concatenate a column's values on subquery

From Dev

Concatenate values which don't exist in the column

From Dev

Concatenate Column Values Row by Row Dynamically

From Dev

Pivot and concatenate values from column in SQL Server

Related Related

  1. 1

    Concatenate column values

  2. 2

    JPA concatenate STRING column values into a single value just like an aggregate function

  3. 3

    JPA concatenate STRING column values into a single value just like an aggregate function

  4. 4

    Best way to aggregate logging data

  5. 5

    concatenate column name and column values

  6. 6

    Shell script- best way to read column values and store to variable?

  7. 7

    Concatenate mysql column values in php

  8. 8

    Best way to switch values

  9. 9

    C: What is the best and fastest way to concatenate strings

  10. 10

    SQL Server: Best way to concatenate multiple columns?

  11. 11

    C: What is the best and fastest way to concatenate strings

  12. 12

    Column to aggregate values in another one

  13. 13

    Best way to aggregate a simple dict in Python

  14. 14

    Best way to aggregate a simple dict in Python

  15. 15

    What is the best way to index aggregate data on ElasticSearch

  16. 16

    Concatenate column values against another column group

  17. 17

    Concatenate column values in Pandas DataFrame with "NaN" values

  18. 18

    Concatenate characters of string values to the same column values

  19. 19

    Concatenate column values in Pandas DataFrame with "NaN" values

  20. 20

    Aggregate Pandas Column based on values in Column Range

  21. 21

    Mysql best way to increase a column?

  22. 22

    Java compare values, best way

  23. 23

    Best way to add values to an object?

  24. 24

    Java compare values, best way

  25. 25

    Python Pandas: Join on unique column values and concatenate

  26. 26

    SQL Server concatenate a column's values on subquery

  27. 27

    Concatenate values which don't exist in the column

  28. 28

    Concatenate Column Values Row by Row Dynamically

  29. 29

    Pivot and concatenate values from column in SQL Server

HotTag

Archive