1

抜けた髪を引っ張っています!結果セットはすべて良好ですが、今は別のことをする必要があります。これが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.
4

1 に答える 1

3

あなたのコードはルーブリック列だと思います

select documentdate,[Date], [Read Code], [Rubric], [Notes], [Notes1],
[Episodicity],REF.dbo.PATs.OptedOut FROM 
(
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  
,       row_number() over (partition by x.a.value('(Rubric)[1]','varchar(200)') 
        order by x.a.value('(Date)[1]','varchar(50)') desc) as rn
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
) a where rn = 1
于 2011-09-01T11:00:02.437 に答える