I am trying to create a value that concatenates both hard coded strings and strings created using FOR XML PATH
.
SUBSTRING(
(SELECT (', ' + [value])
FROM [values]
FOR XML PATH( '' )
), 3, 1000) +
' text in between my values ' +
SUBSTRING(
(SELECT (', ' + [otherValue])
FROM [otherValues]
FOR XML PATH( '' )
), 3, 1000)
So I would expect something like: Value1, Value2, Value3 text in between my values OtherValue1, OtherValue2, OtherValue3
, but instead I get a blank string.
If I take out the substrings (including the query inside it) I get the values in between fine, and if I only add one of the substring blocks by itself I get the the list string back. So I can't work out why having concatenation with the substring and FOR XML PATH
queries causes it return an empty string.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…