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
There are a tremendous answers already. I just wanted to add that you can also use styles within your query which might be a good in terms of design.
BEGIN
SET NOCOUNT ON;
DECLARE @htmlOpenTable VARCHAR(200) =
''
DECLARE @htmlCloseTable VARCHAR(200) =
'
'
DECLARE @htmlTdTr VARCHAR(max) = (
SELECT
'border-top: 1px solid #2c3e50' as [td/@style], someColumn as td, '',
'border-top: 1px solid #2c3e50' as [td/@style], someColumn as td, ''
FROM someTable
WHERE someCondition
FOR XML PATH('tr')
)
SELECT @htmlOpenTable + @htmlTdTr + @htmlCloseTable
END
Where someColumn
is your attribute from your table
And someTable
is your table name
And someCondition
is optional if you are using WHERE
claus
Please note that the query is only selecting two attributes, you can add as many as you want and also you can change on the styles.
Of course you can use styles in other ways. In fact, it is always better to use external CSS, but it is a good practice to know how to put inline styles because you might need them