Hi All,
I got a issue in query() method of xquery when i am trying to solve the arithmetic expression .
the problem is that
when i use the sql statments like this
DECLARE @x xml=''
DECLARE @x1 xml;
DECLARE @Result DECIMAL(38,8)
SET @x1= @x.query('1*12')
SET @Result= CAST(@x1.value('(/.)[1]', 'Float') AS DECIMAL(38,8))
Select @Result
then it returns the value 12.00000000 which is correct
but when i am going to use any variable in place of arithmetic expression like this
DECLARE @x xml=''
DECLARE @x1 xml;
DECLARE @Result DECIMAL(38,8)
DECLARE @r varchar(60)='1*12'
SET @x1= @x.query(@r)
SET @Result= CAST(@x1.value('(/.)[1]', 'Float') AS DECIMAL(38,8))
Select @Result
then it gives the error
The argument 1 of the XML data type method "query" must be a string literal.
i also tried
SET @x1= @x.query('sql:variable("@r")')
but it only gives only 1*12 not the value.
Please help me .