Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-02-17 : 08:20:13
|
| Jorge writes "Dear friends,I need to get an information from a XML node and this content is inside of a text field called "XMLContent" from a table called "TBL_SIMULATION"Here the script:Create Function getProductID(@XMLContent text, @SearchFor char(4))returns intasbegin declare @idoc int declare @ProductID int declare @XML_XPath varchar(8000) set @XML_XPath = '//simulation/products/product[@released=' + @SearchFor + ']' EXEC sp_xml_preparedocument @XMLContent OUTPUT, @idoc SELECT @ProductID = product_id FROM OPENXML (@idoc, @XML_XPath,1) WITH (product_id int) EXEC sp_xml_removedocument @idoc return(@ProductID) End goselect prm.dbo.getProductID(XMLContent, '1999') from prm.dbo.Tbl_Simulationwhere Simulation_ID = 316goWhen I run the code above I got an error message:Server: Msg 557, Level 16, State 2, Procedure getProductID, Line 12Only functions and extended stored procedures can be executed from within a function.Does anyone could help me?Thanks in advance.Jorge" |
|
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2004-02-17 : 08:52:51
|
| sp_xml_removedocument can not be executed from within a function. You can rewrite this function as a stored procedure. |
 |
|
|
safigi
Starting Member
15 Posts |
Posted - 2004-02-17 : 16:19:44
|
| try this:SELECT a.*FROM OPENROWSET('SQLOLEDB','yoursqlservername';'sa';'pwd','DECLARE @idoc intDECLARE @doc varchar(1000)SET @doc =''<ROOT><Customer CustomerID="VINET" ContactName="Paul Henriot"> <Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00"> <OrderDetail OrderID="10248" ProductID="11" Quantity="12"/> <OrderDetail OrderID="10248" ProductID="42" Quantity="10"/> </Order></Customer><Customer CustomerID="LILAS" ContactName="Carlos Gonzlez"> <Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00"> <OrderDetail OrderID="10283" ProductID="72" Quantity="3"/> </Order></Customer></ROOT>''--Create an internal representation of the XML document.EXEC sp_xml_preparedocument @idoc OUTPUT, @doc-- Execute a SELECT statement that uses the OPENXML rowset provider.SELECT *FROM OPENXML (@idoc, ''/ROOT/Customer'',1) WITH (CustomerID varchar(10), ContactName varchar(20))') as asafi |
 |
|
|
|
|
|
|
|