|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, March 08, 2013 1:52 PM
Points: 29,
Visits: 86
|
|
Okay all, just got out of a meeting and went back to it. I think I have it all sorted except for one, tiny portion:
, 'StorageLocation' = STUFF ( ( 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 ).value('.','varchar(max)') ,1 ,1 ,'' )
This is the section I am a bit stuck on:
).value('.','varchar(max)') I have read that .value() is an XQury function that accepts an XML data type and converts it to SQL Server data type. Makes sense. From MSDN: value (XQuery, SQLType), where "XQuery - is the XQuery expression, a string literal, that retrieves data inside the XML instance" and "SQLType - Is the preferred SQL type."
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?
Thanks.
Kurt
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 9:55 PM
Points: 6,720,
Visits: 11,759
|
|
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
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, March 08, 2013 1:52 PM
Points: 29,
Visits: 86
|
|
Excellent! That's what I thought. Thanks.
Kurt
|
|
|
|