Python Forum
Execute SQL Server Stored Procedures - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Execute SQL Server Stored Procedures (/thread-28595.html)



Execute SQL Server Stored Procedures - eslamerman - Jul-25-2020

Hi,

I would like to execute the below statment using python on sql server. The statment is working on sql sqerver. But when i tried to execute as sql from python it fails. Any idea how to run in directly?!

Output:
#sqlserver #storedprocedure --List the DBName, SchemaName, table Name, ROWCOUNT, DATA SIZE --for ALL the database in specific server declare @SprocsTableCount as Table ( dbname varchar(128), SchemaName varchar (128), ObjectName VarChar(128), rowscount int, DataSize int, createddate datetime, modifydate datetime ) insert into @SprocsTableCount execute sp_MSforeachdb N'use [?]; select ''?'' ,SchemaName=s.name ,TableName=t.name ,p.rows ,DataInKB=sum(a.used_pages)*8 ,CreateDate=t.create_date ,ModifyDate=t.modify_date FROM sys.schemas s JOIN sys.tables t on s.schema_id=t.schema_id JOIN sys.partitions p on t.object_id=p.object_id JOIN sys.allocation_units a on a.container_id=p.partition_id GROUP BY s.name, t.name, t.create_date, t.modify_date, p.rows ORDER BY SchemaName, TableName' select dbname as DbName,SchemaName as SchemaName,ObjectName,rowscount as Rows,DataSize as DataInKB ,createddate as CreateDate,modifydate as ModifyDate from @SprocsTableCount order by dbname



RE: Execute SQL Server Stored Procedures - Larz60+ - Jul-25-2020

please show python code, and where it fails.


RE: Execute SQL Server Stored Procedures - elenaflorence87 - Jul-25-2020

@eslamerman the programme structure is mistake. here im sharing brief explaination about execution SQl once look into this , i feel this will helps you.
https://docs.microsoft.com/en-us/sql/relational-databases/stored-procedures/execute-a-stored-procedure?view=sql-server-ver15


RE: Execute SQL Server Stored Procedures - eslamerman - Jul-26-2020

(Jul-25-2020, 02:07 PM)Larz60+ Wrote: please show python code, and where it fails.
I don't have a python code. I want to know how to execute this using python.
When I execute it from SSMS, it returns a result.


RE: Execute SQL Server Stored Procedures - vikramprabhu - Oct-21-2020

I am trying to read OUT Parameter from an Oracle Stored Procedure which is an array.

Oracle Stored Proc:
create or replace PROCEDURE PRC_LV_FASTREPORT_RPT (v_start_date IN DATE, v_end_date IN DATE,l_nt OUT LV_FASTREPORT_RPT_tab)


Python Call:
---
cur = conn.cursor()
args = (date_from.__format__('%d-%b-%Y'),date_to.__format__('%d-%b-%Y'), 0)
result_args = cur.callproc('PRC_LV_FASTREPORT_RPT', args)
----

Error I get:
wrong number or types of arguments in call to 'PRC_LV_FASTREPORT_RPT'

---

Can you please let me know if I am doing anything wrong?
Is it the right way to read an Array Output from Stored Proc?



Thank you,
- VP