Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. DB2 to SQL conversion

DB2 to SQL conversion

Scheduled Pinned Locked Moved Database
databasexmlhelp
3 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10250634
    wrote on last edited by
    #1

    I ned to convert below DB2 query to SQL

    SUBSTR(xmlserialize(xmlagg(xmltext(CONCAT( ', ',DEL.COVERAGE_CODE))) as VARCHAR(1024)), 3) as COVERAGE_CODE

    I am not able to get equivalents of xml related things in SQL. Any help would be appreciated

    V Richard DeemingR 2 Replies Last reply
    0
    • U User 10250634

      I ned to convert below DB2 query to SQL

      SUBSTR(xmlserialize(xmlagg(xmltext(CONCAT( ', ',DEL.COVERAGE_CODE))) as VARCHAR(1024)), 3) as COVERAGE_CODE

      I am not able to get equivalents of xml related things in SQL. Any help would be appreciated

      V Offline
      V Offline
      Victor Nijegorodov
      wrote on last edited by
      #2

      Search for xml-equivalents in TSQL: [Using XML Serialization with SQL's FOR XML PATH](https://www.codeproject.com/Articles/21379/Using-XML-Serialization-with-SQL-s-FOR-XML-PATH) [Using XML Serialization with C# and SQL Server - TechNet Articles - United States (English) - TechNet Wiki](https://social.technet.microsoft.com/wiki/contents/articles/28151.using-xml-serialization-with-c-and-sql-server.aspx) [](https://msdn.microsoft.com/en-us/library/jj161200(v=sql.105).aspx?f=255&MSPPError=-2147217396)

      1 Reply Last reply
      0
      • U User 10250634

        I ned to convert below DB2 query to SQL

        SUBSTR(xmlserialize(xmlagg(xmltext(CONCAT( ', ',DEL.COVERAGE_CODE))) as VARCHAR(1024)), 3) as COVERAGE_CODE

        I am not able to get equivalents of xml related things in SQL. Any help would be appreciated

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        For that specific query, there are various equivalent methods in SQL: Concatenating Row Values in Transact-SQL - Simple Talk[^]

        STUFF
        (
        (
        SELECT ', ' + DEL2.COVERAGE_CODE
        FROM YourTable As DEL2
        WHERE DEL2.GroupingField = DEL.GroupingField
        FOR XML PATH(''), TYPE
        ).value('.', 'varchar(max)'),
        1, 2, ''
        )

        Or, if you're using SQL 2017, you can use the new STRING_AGG function: STRING_AGG (Transact-SQL) | Microsoft Docs[^]

        STRING_AGG(DEL.COVERAGE_CODE, ', ')


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups