I am trying to run a system SP (which is a pre-built) using python pyodbc
. In fact I am trying to see the dependencies on a table using sp_depends '<Object name>';
I am using the below code snippet.
df_f=[]
l_table = ['table_1','table_2','table_3']
try:
for l in l_table:
sql = """EXEC sp_depends '{0}';""".format(l)
while cur.nextset():
cur.execute(sql)
c = cur.fetchall()
df_l= pd.DataFrame.from_records(c, columns = [desc[0] for desc in cur.description])
df_l['Referenced_Object'] = l
df_f.append(df_l)
break
except pyodbc.Error as err:
s = str(err)
print(s)
finally:
cur.close()
cnxn.close()
The above code is not running. It is not throwing error but not appending anything in df_f
.
If I run the above SP separately, I am getting the below error:
ProgrammingError: No results. Previous SQL was not a query.
I have taken help from this SO thread.
I am not able to SET NOCOUNT ON
in this SP as this is a built-in and therefore I am not able to get the desired information in dataframe.
Any clue on this?