Skip to content Skip to sidebar Skip to footer

Python: Execute Stored Procedure With Parameters

I'm working on a Python script that writes records from a stored procedure to a text file. I'm having issues executing the stored procedure with parameters. I'm not sure what I cou

Solution 1:

I was able to fix the syntax error by removing the parenthesis from the query string.

# Execute stored procedurestoredProc = "exec database..stored_procedure('param1', 'param2')"

should be

# Execute stored procedurestoredProc = "exec database..stored_procedure 'param1','param2'"

Solution 2:

This worked for me

query = "EXEC [store_proc_name] @param1='param1', @param2= 'param2'"
cursor.execute(query)

Solution 3:

For SQL Server:

cursor.execute('{call your_sp (?)}',var_name)

Post a Comment for "Python: Execute Stored Procedure With Parameters"