2017-06-14 4 views
0

CR.DestinationDepotのレコードが2つあるかどうかを調べるために、今すぐ連結する方法とは対照的に(例えば)KNI/KHNのように連結します。何か案は?ありがとうございました。カウントを使用して出現を決定し、データを連結する

enter image description here

select CR.DestinationCountry, 
mm.MovementRef, 
CR.DestinationDepot, 
case when count(CR.DestinationDepot) >= 2 then 'yes' else 'no' end as [statement], 
Case when (CR.DestinationCountry <> 'GB') and count(CR.DestinationDepot) >= 2 then CR.DestinationDepot+'/'+CR.DestinationDepot else CR.DestinationDepot end as [DestinationDepot] 
FROM dbo.MALExport AS ME 
    INNER JOIN dbo.movConLink AS MCL ON ME.ConsignmentReference = MCL.ConsignmentReference 
    INNER JOIN dbo.cgtRoute AS CR ON CR.RouteID = MCL.CMRRouteID 
    INNER JOIN dbo.movMovement AS MM ON MM.MovementRef = ME.MovementReference 
    group by cr.DestinationCountry, cr.DestinationDepot, mm.MovementRef 

答えて

0

次のコードは、あなたが

select CR.DestinationCountry, 
mm.MovementRef, 
CR.DestinationDepot, 
case when count(CR.DestinationDepot) >= 2 then 'yes' else 'no' end as [statement], 
Case when (CR.DestinationCountry <> 'GB') and count(CR.DestinationDepot) >= 2 then CR.DestinationDepot+'/'+CR.DestinationDepot else CR.DestinationDepot end as [DestinationDepot] 
,stuff((SELECT '/' + CR2.DestinationDepot' ' FROM dbo.cgtRout cr2 
    WHERE CR.DestinationCountry <> 'GB' and CR2.RouteID = MCL.CMRRouteID order by CR2.RouteID desc FOR XML PATH('')),1,1,'') AS [DestinationDepot2] 
FROM dbo.MALExport AS ME 
    INNER JOIN dbo.movConLink AS MCL ON ME.ConsignmentReference = MCL.ConsignmentReference 
    INNER JOIN dbo.cgtRoute AS CR ON CR.RouteID = MCL.CMRRouteID 
    INNER JOIN dbo.movMovement AS MM ON MM.MovementRef = ME.MovementReference 
    group by cr.DestinationCountry, cr.DestinationDepot, mm.MovementRef 
+0

こんにちは@RJ_残念ながら、このコードを実行しても問題が解決しなかった探しているものでなければなりません。とにかくありがとうございました –

関連する問題