Link to home
Start Free TrialLog in
Avatar of Taras
TarasFlag for Canada

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.
SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia 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
ASKER CERTIFIED 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 Taras

ASKER

Thank you very much to all of you. Purpose of this script was to  prepare result for export to excel. User  wanted it on that way presented. I had to put in additional part that will calculated number of notes so the number of column can be dynamic, Here I used number 30 but in reality it will be in range  from 10  to 15.
Thank you all.
Avatar of Taras

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
Avatar of Ramesh D Jaiswal
Ramesh D Jaiswal

Excellent best solution Ryan