J
Jeff Donnici
We've got a .NET (WinForms) application that talks to a read-only SQL Server
database (it's a reference tool that the user can't modify). On the user's
local machine, however, they can store some "favorites" ... these are stored
as very simple XML files with the IDs for the widgets they want to save as a
"favorite". As a side note, the application talks to the database only
through stored procedures (there's no in-line SQL in the C# code).
Later, the user wants to run a query that returns information related only
to their favorite widgets (via either a join or a subquery). To do this,
we're toying with code similar to what's pasted below (modified from the
samples, using data/structures from Northwind).
The problem is that it's VERY LIKELY that the string containing the XML will
exceed 8000 characters. In experimenting with this, it looks like a TEXT
datatype can't be used in the procedure (when replacing the varchar(8000)
with text).
So, my questions are:
1 - What is the size limitation on the XML string that can be passed to
sp_xml_preparedocument?
2 - Are there any drawbacks to passing the XML to our own stored proc as a
TEXT parameter (not a local variable) and sending that directly to
sp_xml_preparedocument?
3- Most importantly -- Given what we want to do (join an XML-based set of
IDs to SQL Server data), is there a better/cleaner/faster way to go than
this OPENXML route?
Thanks in advance for any assistance.
Regards,
JD
CODE BELOW
==================================
DECLARE @idoc int
DECLARE @doc varchar(8000)
SET @doc ='
<ROOT>
<Customer CustomerID="BERGS" ContactName="Berglunds"></Customer>
<Customer CustomerID="FAMIA" ContactName="Familia"></Customer>
<Customer CustomerID="LAZYK" ContactName="The Lazy K"></Customer>
<Customer CustomerID="THECR" ContactName="Cracker Box"></Customer>
</ROOT>'
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
SELECT xtab.ContactName, rtab.Address
FROM Customers rtab,
OPENXML (@idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20)) xtab
WHERE rtab.CustomerID = xtab.CustomerID
database (it's a reference tool that the user can't modify). On the user's
local machine, however, they can store some "favorites" ... these are stored
as very simple XML files with the IDs for the widgets they want to save as a
"favorite". As a side note, the application talks to the database only
through stored procedures (there's no in-line SQL in the C# code).
Later, the user wants to run a query that returns information related only
to their favorite widgets (via either a join or a subquery). To do this,
we're toying with code similar to what's pasted below (modified from the
samples, using data/structures from Northwind).
The problem is that it's VERY LIKELY that the string containing the XML will
exceed 8000 characters. In experimenting with this, it looks like a TEXT
datatype can't be used in the procedure (when replacing the varchar(8000)
with text).
So, my questions are:
1 - What is the size limitation on the XML string that can be passed to
sp_xml_preparedocument?
2 - Are there any drawbacks to passing the XML to our own stored proc as a
TEXT parameter (not a local variable) and sending that directly to
sp_xml_preparedocument?
3- Most importantly -- Given what we want to do (join an XML-based set of
IDs to SQL Server data), is there a better/cleaner/faster way to go than
this OPENXML route?
Thanks in advance for any assistance.
Regards,
JD
CODE BELOW
==================================
DECLARE @idoc int
DECLARE @doc varchar(8000)
SET @doc ='
<ROOT>
<Customer CustomerID="BERGS" ContactName="Berglunds"></Customer>
<Customer CustomerID="FAMIA" ContactName="Familia"></Customer>
<Customer CustomerID="LAZYK" ContactName="The Lazy K"></Customer>
<Customer CustomerID="THECR" ContactName="Cracker Box"></Customer>
</ROOT>'
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
SELECT xtab.ContactName, rtab.Address
FROM Customers rtab,
OPENXML (@idoc, '/ROOT/Customer',1)
WITH (CustomerID varchar(10),
ContactName varchar(20)) xtab
WHERE rtab.CustomerID = xtab.CustomerID