Here's one approach:
-- Sample Data
DECLARE @tblX TABLE (cID int identity, cSettings xml);
INSERT @tblX (cSettings)
VALUES
('<PreviousItem>
<string>501</string>
<string>502</string>
<string>505</string>
</PreviousItem>'),
('<PreviousItem>
<string>4433</string>
<string>5577</string>
</PreviousItem>');
-- Solution
SELECT
cID,
PreviousItem = STUFF
(
(
SELECT ',' + x.value('(text())[1]', 'varchar(500)')
FROM @tblX t
CROSS APPLY cSettings.nodes('/PreviousItem/string') x(x)
WHERE t.cID = tx.cId
FOR XML PATH('')
),1,1,''
)
FROM @tblX tx;
Based on your sample data you have a RegistrationType that lives in your XML that you need to get... Here's a tweaked version of my first solution.
-- Updated Sample Data with RegistrationType
DECLARE @tblX TABLE (cID int identity, cSettings xml);
INSERT @tblX (cSettings)
VALUES
('<PreviousItem>
<string>501</string>
<string>502</string>
<string>505</string>
</PreviousItem>
<RegistrationType>Type A</RegistrationType>
'),
('<PreviousItem>
<string>4433</string>
<string>5577</string>
</PreviousItem>
<RegistrationType>Type B</RegistrationType>
');
-- Solution which includes RegistrationType
SELECT
cID,
PreviousItem = STUFF
(
(
SELECT ',' + x.value('(text())[1]', 'varchar(500)')
FROM @tblX t
CROSS APPLY cSettings.nodes('/PreviousItem/string') x(x)
WHERE t.cID = tx.cId
FOR XML PATH('')
),1,1,''
),
RegistrationType = STUFF
(
(
SELECT ',' + x.value('(text())[1]', 'varchar(500)')
FROM @tblX t
CROSS APPLY cSettings.nodes('RegistrationType') x(x)
WHERE t.cID = tx.cId
FOR XML PATH('')
),1,1,''
)
FROM @tblX tx;
For a more accurate solution please include some DDL and consumable sample data and I can modify my solution accordingly.
Update: because your XML data is stored as text you would need to tweak my original solution like so:
-- Updated Sample Data with RegistrationType
DECLARE @tblX TABLE (cID int identity, cSettings varchar(max));
INSERT @tblX (cSettings)
VALUES
('<PreviousItem>
<string>501</string>
<string>502</string>
<string>505</string>
</PreviousItem>
<RegistrationType>Type A</RegistrationType>
'),
('<PreviousItem>
<string>4433</string>
<string>5577</string>
</PreviousItem>
<RegistrationType>Type B</RegistrationType>
');
-- Solution which includes RegistrationType
SELECT
cID,
PreviousItem = STUFF
(
(
SELECT ',' + x.value('(text())[1]', 'varchar(500)')
FROM @tblX t
CROSS APPLY (VALUES (CAST(cSettings AS xml))) xx(xx)
CROSS APPLY xx.xx.nodes('/PreviousItem/string') x(x)
WHERE t.cID = tx.cId
FOR XML PATH('')
),1,1,''
),
RegistrationType = STUFF
(
(
SELECT ',' + x.value('(text())[1]', 'varchar(500)')
FROM @tblX t
CROSS APPLY (VALUES (CAST(cSettings AS xml))) xx(xx)
CROSS APPLY xx.xx.nodes('RegistrationType') x(x)
WHERE t.cID = tx.cId
FOR XML PATH('')
),1,1,''
)
FROM @tblX tx;