Home > Data > XML Output Linkage > Schema Structure > Using a stored procedure to write XML to SQL

Using a stored procedure to write XML to SQL

You can use a stored procedure to write XML results to SQL Server by checking the Use a stored procedure to write XML results checkbox (on the Schema Structure tab) and then clicking the Params button to define the stored procedure's name and its arguments (the xml results , i.e., <XML results>, is always an argument). After you run a calculation and view the XML or XML+XSL results (under the Options button in the Calculation Results view), you can then choose to write the XML results (or if appropriate, the XML+XSL results) to SQL Server.

On the Params dialog you must specify the Name of the stored procedure you want to call (this stored procedure would be written by your DBA). By default the only argument is <XML results> (the XML or XML+XSL results from an XML Desktop or Server Output Definition), but you can use any scalar value in your XML Output results as an argument.

By clicking on the New... button, you can define a new stored procedure argument by giving it a Name (must be unique within the arguments for this stored procedure; doesn't have to match the actual name of the stored procedure argument in SQL Server, just its type), and then selecting an XML path (XPATH) from the XML Output Linkage's Schema -- this is where the value will come from. Make sure that the type value pointed to by the XPATH (number, string, date) is the "same" as the type as the stored procedure's argument in SQL Server.

After you define the stored procedure's arguments, then you can click on the Re-Order Arguments button to put them into the same order as the stored procedure's arguments in SQL Server (this information can be supplied by your DBA).

When writing the stored procedure, if there's a problem with one of the arguments or assumptions (e.g., this stored procedure shouldn't be run on Plan 132), we suggest checking for those error conditions in the stored procedure (within SQL Server) and then using the SQL function RAISERROR to issue an appropriate error message. For example,

RAISERROR ('You cannot use this stored procedure when the PlanID is 132',16, 1)

where the second argument 16 indicates that this is a user defined error message (vs a SQL Server error message). When this error is generated in SQL, ProAdmin will show the user this error message so they can figure out how to fix the error.