Query XML column and get Group by a XML field value

  • Hi,

    I have table Table A with 3 columns. One of these 3 columns, is an XML  column.

    Col 1: id

    Col 2: Businessday

    Col3: Payload (XML column)

    I have a XML field  root/deptid inside XML payload.

    Now, I need get count (id), businessday, deptid, from Table A group by deptid.

    Select  count(id) , Businessday,  Payload.value(/Root/:deptid)[1]', 'nvarchar(MAX)') as deptNumber

    from Table A

    where cast(businessday as date)='2019-10-10'

    group by businessday, deptnumber

    I'm getting error that I can not group by on XML column.

    Please advise how can I group by with deptNumber?

     

     

     

    • This topic was modified 5 years ago by  IMary.
  • Try shredding your xml in a CTE, then do the count/group by using the CTE as source

    • This reply was modified 5 years ago by  DesNorton.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply