Link to home
Start Free TrialLog in
Avatar of holemania
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?
Avatar of GO-87
GO-87

What you're trying to do, is to apply an AGGREGATE function to the Code column across a bunch of rows, GROUP-ing by the remainder of the fields.

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 
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]