stoperror
Goto Top

MS SQL Server 2005 - Verkettung mit FOR XML PATH Probleme mit Feld, das Source heisst

Ich habe einen funktionierenden XML Path Ausdruck, der mehrere Felder aus der DB in einer Spalte zusammenfügt. Füge ich dort aber noch das Feld Source hinzu, wird nur das erste Element der Verkettung mit Sourcewert ausgegeben

select
reasontext + ' (' + 'erstellt am: ' + convert(varchar(10),creationdate,104) + ' ' + convert(varchar(8), creationdate, 108) +

-- InformationSource hinzugefügt
' InformationSource: ' +
-- das geht
--convert(varchar(100),3) +
-- das nicht
--convert(varchar(100), Source) +


')'
+ ', '
from mytable
FOR XML PATH('')


In Source (int) steht z. B. auch nur die 3 drin.

Im auskommentierten Zustand von Source kommt z. B. das raus:
Reason1 (erstellt am: 03.03.2010 09:13:00 InformationSource: ), Reason 2 (erstellt am: 16.07.2010 11:57:00 InformationSource: ), Reason3 (erstellt am: 20.07.2010 11:19:00 InformationSource: ),

Kommentiere ich die Source - Zeile ein, dann ist das Ergebnis nur:
Reason1 (erstellt am: 03.03.2010 09:13:00 InformationSource: 3,

Das Problem scheint das Feld Source zu sein (die Bezeichnung?).
Kann ich das irgendwie umgehen?

Danke schon mal für die Hilfe!

Content-Key: 153589

Url: https://administrator.de/contentid/153589

Printed on: April 19, 2024 at 18:04 o'clock

Member: stoperror
stoperror Oct 22, 2010 at 12:36:30 (UTC)
Goto Top
Das Problem war ein ganz anderes...
Er hat nur die Sachen verkettet, die auch ein Source gesetzt hatten.
Lösung:

case
when (Source is null) then ' '
else
convert(varchar(max),Source)
end