Link to home
Start Free TrialLog in
Avatar of maxwell2323
maxwell2323

asked on

How to concatenate one field from similar records

I have the results of a select query where all records have totally equal field values except for only one field, where the values are different. What I want to do in T-SQL is basically have just one record, where the one particular field has the unique values concatenated together, perhaps separated by commas or slashes or pipes or something (other than a space). For instance, see the file attached that has the results of the query. I want to get this record below out of the results:   Joe      6/1/2005    Spinal injury,valve disease,migraine

resultsofselectquery.doc
ASKER CERTIFIED SOLUTION
Avatar of dbidba
dbidba
Flag of United States of America 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
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America 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
>>That is using dynamic SQL.<<
You may want to double check that...
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

Hey,

I just made code ready made, but idea was same as Mr.Genius - mwvisa1 tolds...

So check dat link..
Yes Anthony, dynamic SQL is not what I meant. the coalesce approaches depends on filling variable first the using so it works well but will be limited when you can't use multiple statements then can use the xml trick shown...
Kevin
Avatar of maxwell2323
maxwell2323

ASKER

Great stuff. Thanks everyone !