I am facing problems while retrieving data from XML.
with xmlnamespaces ('x-elements' as x)
select
tb.[Profile].value('(x:ppr/x:static/refId)[1]', 'varchar(22)') testCol
from table1 tb
The above code works perfectly fine. But, when I pass the XML path in a function it compiles correctly but doesn't return data upon calling but just the xml path (that is passed to it).
CREATE FUNCTION testFunc
(
@p varchar(22)
)
RETURNS nvarchar(max)
AS
BEGIN
DECLARE @Rs nvarchar(max);
with xmlnamespaces ('x-elements' as x)
select
@Rs = tb.[Profile].value('(sql:variable("@p_path"))[1]', 'nvarchar(max)')
from table1 tb
RETURN (@Rs)
END
The result I am getting is "x:ppr/x:sta" (which is a path not the value) whereas it should return a value like "aJxk9pGntc5V" Please suggest a solution!