Avatar of Taras
Taras
Flag 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.
DatabasesMicrosoft SQL Server

Avatar of undefined
Last Comment
Ramesh D Jaiswal

8/22/2022 - Mon
SOLUTION
PortletPaul

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Mark Wills

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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.
Taras

ASKER
It worked very well. Thank you all very much.
Mark Wills

>> 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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ramesh D Jaiswal

Excellent best solution Ryan