Suppose I have a query like this –
SELECT * FROM
OPENXML(@i, '/root/authors', 2)
WITH authors
Now, I want to pass '/root' via a parameter/variable like –
DECLARE @nodeName varchar(MAX) ----> EDIT: Solution- Use fixed length instead of MAX
SET @nodeName = '/root'
and use @nodeName instead. Then concatenate the rest of the elements dynamically.
I am getting error just by using @nodeName in the OPENXML parameter.
I tried the following in SQL 2008 R2 and it works fine.
It could be that other versions of SQL only support the use of NVARCHAR as a parameter, not VARCHAR.
I hope this help.