Create HTML Table with SQL FOR XML

前端 未结 8 1419
夕颜
夕颜 2020-11-22 08:34

I\'m creating a HL7 Continuity of Care Document (CCD) using FOR XML statements in SQL Server 2008 R2.

I\'ve done A LOT with this method, but this is the first time I

8条回答
  •  醉梦人生
    2020-11-22 08:47

    select 
      (select p.ProblemType     as 'td' for xml path(''), type),
      (select p.Onset           as 'td' for xml path(''), type),
      (select p.DiagnosisStatus as 'td' for xml path(''), type)
    from tblProblemList p
    where p.PatientUnitNumber = @PatientUnitNumber
    for xml path('tr')
    

    To add the header as well you can use union all.

    select 
      (select 'Problem' as th for xml path(''), type),
      (select 'Onset'   as th for xml path(''), type),
      (select 'Status'  as th for xml path(''), type)
    union all         
    select 
      (select p.ProblemType     as 'td' for xml path(''), type),
      (select p.Onset           as 'td' for xml path(''), type),
      (select p.DiagnosisStatus as 'td' for xml path(''), type)
    from tblProblemList p
    where p.PatientUnitNumber = @PatientUnitNumber
    for xml path('tr')
    

提交回复
热议问题