2009-07-20 4 views
3

배경 : SQL FOR XML 쿼리를 사용하여 훨씬 더 큰 XML 문서 (HL7 CDA 문서)를 생성합니다. 관습에 따라,이 XML 노드 앞에 섹션 주석을 포함시켜 노드가 큰 문서로 재구성 될 때 읽을 수있게해야합니다. 내가 주석을 삽입 할 수 있지만SQL FOR XML 문으로 XML 주석 생성

SELECT  '10153-2' AS [section/code/@code], '2.16.840.1.113883.6.1' AS [section/code/@codeSystem], 'LOINC' AS [section/code/@codeSystemName], 
         'Past Medical History' AS [section/title], 
      (SELECT  [Incident] + ' - ' + [IncidentYear] as "item" 
      FROM  [tblSummaryPastMedicalHistory] AS PMH 
      WHERE  ([PMH].[Incident] IS NOT NULL) AND ([PMH].[PatientUnitNumber] = [PatientEncounter].[PatientUnitNumber]) 
      FOR XML PATH('list'), TYPE 
      ) as "section/text" 
FROM   tblPatientEncounter AS PatientEncounter 
WHERE  (PatientEncounterNumber = 6) 
FOR XML PATH('component'), TYPE 

: 여기

<!-- 
******************************************************** 
    Past Medical History section 
******************************************************** 
--> 

<component> 
    <section> 
     <code code="10153-2" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/> 
     <title>Past Medical History</title> 
     <text> 
      <list> 
       <item>COPD - 1998</item> 
       <item>Dehydration - 2001</item> 
       <item>Myocardial infarction - 2003</item> 
      </list> 
     </text> 
    </section> 
</component> 

내가 위의 XML을 렌더링하기 위해 구축 한 XML 문에 대한 SQL입니다 : 여기

가 예상되는 출력의 샘플입니다 이러한 XML 스 니펫을 기본 문서로 재조합하는 제어 기능에서부터 우리는 문서 생성 오류를 피하기 위해 출력과 함께 주석을 생성하는 것이 목표입니다.

몇 가지 시도했지만 SELECT 문과 함께 의견을 생성하는 데 문제가 있습니다. 간단한 문자열을 시도했지만 줄 바꿈 구문을 가져올 수 없었습니다. 어떤 제안?

답변

10

예 :

SELECT [EmployeeKey] 
     ,[ParentEmployeeKey] 
     ,[FirstName] 
     ,[LastName] 
     ,[MiddleName] 
     ,[DepartmentName] AS "comment()" 
    FROM [AdventureWorksDW2008].[dbo].[DimEmployee] 
    FOR XML PATH('Employee'),ROOT('Employees') 

는 생산 : 도움을

<Employees> 
    <Employee> 
    <EmployeeKey>1</EmployeeKey> 
    <ParentEmployeeKey>18</ParentEmployeeKey> 
    <FirstName>Guy</FirstName> 
    <LastName>Gilbert</LastName> 
    <MiddleName>R</MiddleName> 
    <!--Production--> 
    </Employee> 
    <Employee> 
    <EmployeeKey>2</EmployeeKey> 
    <ParentEmployeeKey>7</ParentEmployeeKey> 
    <FirstName>Kevin</FirstName> 
    <LastName>Brown</LastName> 
    <MiddleName>F</MiddleName> 
    <!--Marketing--> 
    </Employee> 
</Employees> 
+0

감사합니다! 반환, 탭 등 내가 실제로 보존하고 싶었던 공백을 실제로 넣어야했습니다. 그 성격에 의한 설명은 태그 등을 인식하지 못하기 때문입니다. –