1 year ago
#93971
Denis Danilov
Method exist in SQL Server does not work correctly with C# parameters @XPath in a request
The method exist for XML object does not work correctly with parameter in SQL request from .NET backend side. In my case, I try to send @XPath
parameter to the request and put whole this one through exist method to select all XML items according to this XPath but as result, I get all non-filtered by these XPath XML from a table.
exec sp_executesql N'SELECT TOP(1000) ord.TrackingID, ord.DateCreate, ord.OrderType, ord.Error_Description, ord.Response, ord.Request
FROM FilteredByXPath AS ord
WHERE (ord.Request.exist(''sql:variable("@XPath")'') = 1)',
N'@TrackingID nvarchar(4000),@ShowAutotestCases bit,@DateFrom datetime,@DateTo datetime,@InputOrderSource nvarchar(1),@Agency int, @XPath nvarchar(max)',
@TrackingID=NULL,@ShowAutotestCases=0,@DateFrom='1753-01-01 00:00:00',@DateTo='9999-12-31 23:59:59.997',@InputOrderSource=N'%',@Agency=0, @XPath=N'//*[text() = "10:33:34.9375000-05:00"]'
Following the exist description I think the ''sql:variable("@XPath")'' returns all time nonempty result and all XML is suitable.
The variants which work well are
WHERE ord.Request.exist(''//*[text() = sql:variable("@XPath")]'') = 1
or
WHERE ord.Request.exist(''//*[text() = "10:33:34.9375000-05:00"]'') = 1
As we see the two variants well when we use XPath as a string directly or @XPath
parameter into XQuery.
The question how can I use @XPath
parameter as a full XQuery expression like in first variant that does not work.
WHERE (ord.Request.exist(''sql:variable("@XPath")'') = 1)
sql-server
xml
sqlxml
0 Answers
Your Answer