是否可以将节点值声明为局部变量,例如
DECLARE @xVal1 <type>;
SET @xVal1 = '/*:OrderWithItems/*:Order/*:ShipServiceLevel)[1]';
,然后在 WHERE 条件下参考下面的@ xVal1,而不是完整的xml路径。
SELECT o.nOrderId AS 'OrderId',
o.Source,
o.Subsource,
lc.cCountry,
CAST(ObjectXML as xml).value('(/*:OrderWithItems/*:Order/*:ShipServiceLevel)[1]', 'NVARCHAR(max)') AS 'ServiceLevel',
CAST(ObjectXML as xml).value('(/*:OrderWithItems/*:Order/*:LatestDeliveryDate)[1]', 'datetime') AS 'LatestDeliveryDate'
FROM [OrderXML] x
INNER JOIN [Open_Order] o ON o.pkOrderId = x.fkOrderId
INNER JOIN [ListCountries] lc ON lc.pkCountryId = o.fkCountryId
WHERE
o.Source = 'AMAZON' AND
o.Subsource IN ('Trimming Shop', 'Wedding Decor - UK') AND
lc.cCountry = 'United Kingdom' AND
x.type = 'Default' AND
CAST(ObjectXML as xml).value('(/*:OrderWithItems/*:Order/*:ShipServiceLevel)[1]', 'NVARCHAR(max)') = 'UK Next' AND
CAST(ObjectXML as xml).value('(/*:OrderWithItems/*:Order/*:LatestDeliveryDate)[1]', 'datetime') = DATEADD(day, 1, GETDATE())
这是结果集:
我想将 LatestDeliveryDate 值转换为日期格式 DD-MM-YYYY