In SQL Server 2008.
I need to execute a query like this:
DECLARE @x AS xml
SET @x=N'<r><c>First Text</c></r><r><c>Other Text</c></r>'
SELECT @x.query('fn:max(r/c)')
But don't return anything (apparently because convert xdt: untypedAtomic to numeric)
How to "drop" r / c in varchar?
Sort of
SELECT @x.query('fn:max(«CAST(r/c «AS varchar(20))»)')
Edit: Using nodes, the MAX function is a T-SQL function no fn: max In this code:
DECLARE @x xml;
SET @x = '';
SELECT @x.query('fn:max((1, 2))');
SELECT @x.query('fn:max(("First Text", "Other Text"))');
expected request return: 2 and Other text fn: max can evaluate the ad hoc string expression. But the first request does not work. How to force string arguments to fn: max?
source
share