-2

How can I write the following in SQL Server 2014 as STRING_AGG function does not work (SQL Server 2016 onwards)

        DECLARE @json_construct VARCHAR(MAX) = '{"type": "TabularTranslator", "mappings": ';

        SELECT CONCAT(
                   @json_construct,
                   '[',
                   STRING_AGG(CONCAT('{"source":{"name":"', c.sourcecolumn, '"},
                   "sink":{"name":"', c.targetcolumn, '"}}'), ','),
                   ']') AS json_output
          FROM ref.RadarColumnMappingConfig AS c
         WHERE c.schemaname = @schemaname
           AND c.viewname   = @viewname;
    END;
jarlh
  • 40,041
  • 8
  • 39
  • 58
Shoaib Maroof
  • 325
  • 1
  • 2
  • 11

0 Answers0