retrieving sql server procedure output variables in python

Say, I have a stored procedure like this:

create procedure delete_po @po_number varchar(100) = null output, @delete_message varchar(200) = ‘deleting..’ output as….

To retrieve the the two output parameters, after the connecting with adodbapi, get the cursor and run this:

po_number = ‘ PO1487’

delete_message = ‘ ‘ * 200

result = cursor.callproc(‘delete_po’, (po_number, delete_message))

The output variables will be in result.

If I added print result to the previous code, I get this output:

[u'PO1487', u'cannot delete PO1487 because there are receiving transactions']

Note that the initial values of the variables (po_number, delete_message) must be initialized with sufficient length to contain the output values. Thus my delete_message = ‘ ‘ * 200.

Custom Search