I have a stored proc with a parameter which I want to have contain an XPath expression which can then be used to retrieve a value in a select, but the r.value(…) exception message says that I can only use literals.
Is this true or is there a way around this?
create proc MySproc
@myxml xml,
@xpath nvarchar(50)
as
begin
select r.value(@xpath, 'nvarchar(100)') as 'demofield'
from @myxml.nodes('/*') as records(r)
end
I have also tried things like r.value('sql:column("@xpath")', 'nvarchar(100)')
Ok, well ultimately I’ve put it all in a dynamic statement. Which, of course, has caused its own troubles…