So I wrote this nice little stored procedure that accepts 3 parameters, assembles a query string, executes a query, and retrieves a single row of data from the specified table.
It then converts the single row into well-formed XML.
The call to EXECUTE query2; is where the XML is returned.
When running it in the Toad MySQL Editor, obviously the XML result shows as a scalar, single column result in the results pane.
Now I need to send that string OUT of this procedure to a calling stored procedure.
I know how to use an OUT parameter, but I don't know how to "capture" the result of executing a prepared statement. Any ideas?
CREATE PROCEDURE sp_ReturnSingleRowAsXml
(
IN RecordID INT,
IN TableName VARCHAR(100),
IN KeyName VARCHAR(100)
)
BEGIN
-- LOTS OF CODE GOES HERE, assembling the xmlQuery string to be executed
SET @xmlQuery = 'SELECT ConvertToXML(@tblName, @pkName, @recID)';
PREPARE query2 FROM @xmlQuery;
EXECUTE query2;
DEALLOCATE PREPARE query2;
END;