But what is the XQuery '.' literal actually doing? Can I *assume* that since an empty string is sent to
FOR XML PATH('')
no root node name is created, and that the '.' argument in the XQuery is just looking at the unnamed root for its data?
As a test, change your code to look like this and see if it makes more sense to see that the FOR XML piece of the query is actually returning an XML document.
The .value is actually just picking up the contents of the root level node of that document, i.e. the '.' node, and casting it to a VARCHAR(MAX).
, 'StorageLocation'
=
(
SELECT ','
+ COALESCE('Rm: ' + lbr2.Room, '')
+ COALESCE(', Cab: ' + ll2.fkCabinet, '')
+ COALESCE(', Bin: ' + CAST(DecryptByKey(ll2.Bin) AS varchar(20)), '')
+ COALESCE(', Box: ' + CAST(DecryptByKey(ll2.Box) AS varchar(20)), '')
+ COALESCE(', ' + CAST(DecryptByKey(ll2.StartColumn) AS varchar(2))
+ CAST(DecryptByKey(ll2.StartRow) AS varchar(2)), '')
+ COALESCE(' --> ' + CAST(DecryptByKey(ll2.EndColumn) AS varchar(2))
+ CAST(DecryptByKey(ll2.EndRow) AS varchar(2)), '')
FROM
dbo.tblLotLocation AS ll2
INNER JOIN
dbo.tblLocationBldgRoom AS lbr2 ON lbr2.pkLocationBldgRoomId = ll2.fkLocationBldgRoomId
WHERE
ll2.fkItemLotId = od.fkItemLotId
ORDER BY
pkLotLocationId
FOR XML PATH(''),
TYPE
)
edit: add quote
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato