I am stuck with a timeout exception in one of my ASP.NET applications and I can blame it upon a SQL Server stored procedure that is causing it to break.
When I saw the execution plan of the procedure, it turned out that almost 99% of the query execution cost is for XML Reader with XPath Filter
. I have actually passed a parameter as CSV
and in my procedure I break it with help of XML Reader
to get my values. But it is not at all efficient for such a simple thing.
Here is my query:
Declare @IDs varchar(max) = '1,2,7,234,74',
@xml xml= ''
Set @xml = N'<root><r>' + replace(@IDs,',','</r><r>') + '</r></root>'
select
t.value('.','varchar(max)') as ID
from
@xml.nodes('//root/r') as a(t)
Any alternative with minor changes available?