Files
mssql-interactions-python/functions/call_func.py
T

38 lines
694 B
Python

import pyodbc
try:
connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes')
cursor = connection.cursor()
sql_cmd="select dbo.ufn_get_cus_code(?) as cus_code"
prm_id=4
cursor.execute(sql_cmd,prm_id)
print("using udf to retrieve cus code...")
while 1:
row = cursor.fetchone()
if not row:
break
print("Customer code for id ", prm_id, " - ", row.cus_code)
print()
cursor.close()
connection.close()
except pyodbc.Error as ex:
print()
print("exception: ",ex)
cursor.close()
connection.close()
print()
exit()
print()