0

I am trying to find the best way to consolidate the string in the fields that have the same value. Please look at the example below:

Table1:

Column1 | Column2 | Column3 | Column4
test1     test2     test3     string1
test1     test2     test3     string2
test4     test5     test6     string3
test4     test5     test6     string4

The result need to be inserted to Table2 like following:

Table2:

Column1 | Column2 | Column3 | Column4
test1     test2     test3     string1 string2
test4     test5     test6     string3 string4

I need to avoid Cursors please. Thank you. Please note: I can not use the XML PATH.

The following query wouldn't work:

SELECT
      m.Column1,m.Column2,m.Column3
    , Column4 = STUFF((
          SELECT ' ' + Column4
          FROM dbo.Table1
          FOR XML PATH(''), TYPE).value('.', 'varchar(max)'), 1, 1, '')
FROM dbo.Table1 m
user3314399
  • 317
  • 4
  • 9
  • 23

0 Answers0