holemania
asked on
SQL Query - Combine 2 or more lines together
Hello experts,
I created a query to pull items off a sql server 2005 database. It is pulling what I need, but is it possible to group 2 or more line items together? The only issue with grouping is that 2 record would be the same except for a field. I want to combine those 2 items as if it's one.
Example:
ID Description Code Date Due
1234 This is a test. ABC 8/25/2010
1234 This is a test. EFT 8/25/2010
Both of the above combined to look like:
ID Description Code Date Due
1234 This is a test. ABC, EFT 8/25/2010
Is it possible?
I created a query to pull items off a sql server 2005 database. It is pulling what I need, but is it possible to group 2 or more line items together? The only issue with grouping is that 2 record would be the same except for a field. I want to combine those 2 items as if it's one.
Example:
ID Description Code Date Due
1234 This is a test. ABC 8/25/2010
1234 This is a test. EFT 8/25/2010
Both of the above combined to look like:
ID Description Code Date Due
1234 This is a test. ABC, EFT 8/25/2010
Is it possible?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
please see the FOR XML PATH stuff:
http://blog.shlomoid.com/2008/11/emulating-mysqls-groupconcat-function.html
http://blog.shlomoid.com/2008/11/emulating-mysqls-groupconcat-function.html
Unfortunately, you cannot use SUM since it only works on numeric values. Instead, you need a sort of AGGREGATE CONCATENATION function.
You can find some examples here:
http://p2p.wrox.com/sql-language/1661-aggregate-concatenation.html