2016-12-21 1 views
2

Bitte könnten Sie mir helfen. Ich mache etwas falsch.Joining in Unterabfragen - STUFF

SELECT   
    EventSpotsJoin.Event, Links.LongLat 
FROM 
    EventSpotsJoin 
INNER JOIN 
    Links ON EventSpotsJoin.Spot = Links.IdLinks 
ORDER BY 
    EventSpotsJoin.Event 

Ergebnis ist

2054 39.0440182, -74.7659984 
2054 28.29555, -80.60898333333333 
2068 39.0440182, -74.7659984 
2068 28.29555, -80.60898333333333 

Und ich möchte lat lang in einer Reihe verbinden. Ich benutze diesen Code.

SELECT 
    [EventSpotsJoin].[Event], 
    STUFF((SELECT '|' + CAST(Links.LongLat AS nvarchar) 
      FROM [dbo].[EventSpotsJoin] 
      WHERE EventSpotsJoin.Spot = Links.IdLinks 
      FOR XML PATH ('')), 1, 1, '') 
FROM    
    EventSpotsJoin 
INNER JOIN 
    Links ON EventSpotsJoin.Spot = Links.IdLinks 
ORDER BY 
    EventSpotsJoin.Event 

und das Ergebnis ist falsch:

2054 39.0440182, -74.7659984|39.0440182, -74.7659984 
2054 28.29555, -80.60898333333333|28.29555, -80.60898333333333 
2068 39.0440182, -74.7659984|39.0440182, -74.7659984 
2068 28.29555, -80.60898333333333|28.29555, -80.60898333333333 

Ich brauche es von Event-Gruppe und kommen Sie nicht die gleiche lat lange Folge.

Antwort

2

starten: Unter der Annahme, dass Sie erwarten, für Ereignis-ID löschte 205439.0440182, -74.7659984|28.29555, -80.60898333333333

SELECT [EventSpotsJoin].[Event], STUFF(
    (SELECT '|' + CAST(Links.LongLat AS nvarchar) 
     FROM Links 
     WHERE EventSpotsJoin.Spot = Links.IdLinks 
     FOR XML PATH ('')) 
    , 1, 1, '') 
FROM EventSpotsJoin 
ORDER BY EventSpotsJoin.Event 
+0

ist Ja, ich erwarte genau das, was Sie gesagt haben. Aber Ergebnis ist immer noch falsch :(Jeder lat lange in separater Zeile. 39,0440182, -74,7659984 28,29555, -80,60898333333333 39,0440182, -74,7659984 28,29555, -80,60898333333333 –

+0

Yes I Ich habe dieses Skript einfach kopiert ... –

+0

Ich bin zweifelhaft in dieser 'EventSpotsJoin.Spot = Links.IdLinks' Bedingung, da für das Ereignis 2054 in der Tabelle –