抜けた髪を引っ張っています!結果セットはすべて良好ですが、今は別のことをする必要があります。これがT-SQLです
SELECT documentdate
, x.a.value('(Date)[1]','varchar(50)') as [Date]
, x.a.value('(ReadCode)[1]','varchar(50)') as [Read Code]
, x.a.value('(Rubric)[1]','varchar(200)') as [Rubric]
, x.a.value('(Notes)[1]','varchar(200)') as [Notes]
, x.a.value('(Notes1)[1]','varchar(200)') as [Notes1]
, x.a.value('(Episodicity)[1]','varchar(50)') as [Episodicity]
, REF.dbo.PATs.OptedOut
FROM
EPR.dbo.PCTX_CONT t INNER JOIN
REF.dbo.PATNumbers
ON t.PATNoID = REF.dbo.PATNumbers.PATNoID
INNER JOIN
REF.dbo.PATs ON
REF.dbo.PATNumbers.CurrentNo =
REF.dbo.PATs.ManorNo
CROSS APPLY
t.DocumentXML.nodes('//CONT') x(a)
WHERE REPLACE(REF.dbo.PATNumbers.CurrentNo,' ','')=123456789
結果は
2010-05-13 8I64.
2010-05-13 8I6C.
2010-02-09 8I24.
2010-02-09 8I65.
2010-02-09 8I26.
2010-02-09 8I6B.
2009-06-02 8I24.
2009-03-17 8I26.
2009-01-06 8I64.
2009-01-06 8I6C.
2006-11-14 8I74.
2006-11-14 8I75.
ただし、必要なのはコードの最新の行なので、結果は次のようになります。
2010-05-13 8I64.
2010-05-13 8I6C.
2010-02-09 8I24.
2010-02-09 8I65.
2010-02-09 8I26.
2010-02-09 8I6B.
2006-11-14 8I74.
2006-11-14 8I75.