Taras
asked on
Concatenate rows
I have table tblNote in SQLServer database
with next fields
Note_ID Note_Date CreatedBy Notes
1 2014-06-25 18:47:03 John Borkovic Test Note adfadf
1 2014-06-25 18:52:28 Jim Jonson Test Note adfadf
2 2014-06-25 18:55:05 Bill Smith Test Notes alkdfakd
3 2014-06-25 18:58:31 Kathy Story Test Notes alkdl
3 2014-06-25 19:27:30 Bill Smith Test Notes abagab
......
I need script that will do merge - Concatenate those rows per Note ID to look like
Note_ID NoteDate_1 CreatedBy_1 Notes_1 NoteDate_2 CreatedBy_2 Note_2
1 2014-06-25 18:47:03 John Borkovic Test Note adfadf 2014-06-25 18:52:28 Jim Jonson Test Note adfadf
2 2014-06-25 18:55:05 Bill Smith Test Notes alkdfakd Null Null Null
3 2014-06-25 18:58:31 Kathy Story Test Notes alkdl 2014-06-25 19:27:30 Bill Smith Test Notes abagab
Per one Note_ID I could have more entries here I my example I have the most two,
but it could be up to 30 entries per Note ID, so I could have 30 x 3 = 90 columns in result.
with next fields
Note_ID Note_Date CreatedBy Notes
1 2014-06-25 18:47:03 John Borkovic Test Note adfadf
1 2014-06-25 18:52:28 Jim Jonson Test Note adfadf
2 2014-06-25 18:55:05 Bill Smith Test Notes alkdfakd
3 2014-06-25 18:58:31 Kathy Story Test Notes alkdl
3 2014-06-25 19:27:30 Bill Smith Test Notes abagab
......
I need script that will do merge - Concatenate those rows per Note ID to look like
Note_ID NoteDate_1 CreatedBy_1 Notes_1 NoteDate_2 CreatedBy_2 Note_2
1 2014-06-25 18:47:03 John Borkovic Test Note adfadf 2014-06-25 18:52:28 Jim Jonson Test Note adfadf
2 2014-06-25 18:55:05 Bill Smith Test Notes alkdfakd Null Null Null
3 2014-06-25 18:58:31 Kathy Story Test Notes alkdl 2014-06-25 19:27:30 Bill Smith Test Notes abagab
Per one Note_ID I could have more entries here I my example I have the most two,
but it could be up to 30 entries per Note ID, so I could have 30 x 3 = 90 columns in result.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
It worked very well. Thank you all very much.
>> Purpose of this script was to prepare result for export to excel.
Ah-ha which explains the phrase merge-concatenate. Also explains the columnar style format...
Thank You for your feedback. Much appreciated getting that clarification.
Great to see you found your solution here. It was a pleasure to be able to help, and to collaborate with 2 fine experts in Paul and Ryan.
Cheers,
Mark Wills
Ah-ha which explains the phrase merge-concatenate. Also explains the columnar style format...
Thank You for your feedback. Much appreciated getting that clarification.
Great to see you found your solution here. It was a pleasure to be able to help, and to collaborate with 2 fine experts in Paul and Ryan.
Cheers,
Mark Wills
Excellent best solution Ryan
ASKER
Thank you all.