I am looking at app data where free text is allowed only 100 characters per DB entry. If it goes over 100 then a new row is created in the DB.
I've looked at this solution and tried to implement it. It's not working as I expect it. How to concatenate text from multiple rows into a single text string in SQL server?
Data Structure:
NAME_ID NAME ATXR_SOURCE_ID ATSY_ID ATXR_DESC Note
500 Jane 463495.0251 ATN0 Affiliation Add dfsdfsfdsafdsadfsadfdsafsadsfdasfd
500 Jane 463495.0251 ATN0 Affiliation Add asdfdsfdsafdafdasdfsadfsadfsadfadfsa
500 Jane 463495.0251 ATN0 RITM0072237 Update to record
500 Jane 463495.0251 ATN0 RITM0074636 Script update
500 Jane 463495.0251 ATN0 RITM0079507 Services updated
SELECT DISTINCT ST2.NAME_ID, ST2.NAME, ST2.ATXR_DESC, ST2.Note,
SUBSTRING(
(
SELECT NAME_ID, NAME, ATXR_SOURCE_ID, ATSY_ID, ATXR_DESC, ','+ Note AS [text()]
FROM #Notes ST1
WHERE ST1.ATXR_DESC = ST2.ATSY_ID
ORDER BY ST1.Note
FOR XML PATH ('')
), 2, 1000) [Students]
FROM #Notes ST2
Actual:
NAME_ID NAME DESC Note Students
500 Jane Affiliation Add dfsdfsfdsafdsadfsadfdsafsadsfdasfd NULL
500 Jane Affiliation Add asdfdsfdsafdafdasdfsadfsadfsadfadfsa NULL
500 Jane TicketA Update to record NULL
500 Jane TicketB Script update NULL
500 Jane TicketC Services updated NULL
Expected (For rows 1 and 2 I want the Notes to be "concatenated"):
NAME_ID NAME DESC Note Students
500 Jane Affiliation Add dfsdfsfdsafdsadfsadfdsafsadsfdasfdasdfdsfdsafdafdasdfsadfsadfsadfadfsa NULL
500 Jane TicketA Update to record NULL
500 Jane TicketB Script update NULL
500 Jane TicketC Services updated NULL