Monday, May 30, 2011

CROSS APPLY

 select  diIdDocument, nopDenumireDocument   into #1  
    from OJ_DocumenteIncarcate
    inner join OJ_TipuriDocumenteSolicitare on diIdDocument = tdsIdDocument
    inner join OJ_NomOpisDocumente on nopIdOpisDocument = tdsIdTipDocument        
               
select distinct diIdDocument, DocumenteAtasate
into #docTypes        
    from #1 a           
CROSS APPLY ( SELECT nopDenumireDocument + '; '               
              FROM #1 b               
              WHERE a.diIdDocument = b.diIdDocument                
              ORDER BY nopDenumireDocument                
              FOR XML PATH('') )  D ( DocumenteAtasate )               

     drop table #1        
     drop table #docTypes  

No comments:

Post a Comment