sql >> Database teknologi >  >> RDS >> Sqlserver

Opret HTML-tabel med SQL FOR XML

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')

For også at tilføje overskriften kan du bruge 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')


  1. Sådan tilføjes AD/BC-indikatoren til en dato i Oracle

  2. Smukke blokke af kedelplade

  3. MySQL-sætning tager mere end minut at udføre

  4. Hvordan beregner man konverteringsrate i MySQL?