I am trying to make a script that will run a stored procedure and then return the values. A simple enough script. As I run the script it is only returning the output of the first query in my stored procedure. When the call is made I have the values being appended to a list. Once the list is created I have it printing onto a GUI that I have made. My stored procedure does work and returns the values for all the queries it contains when run on SSMS. My stored procedure is as follows (Sorry if these are poorly made stored procedures, I am fairly new to SQL):
It takes a parameter @username
Select username,user_id,user_type
from db1.users
where username like '%' + TRIM(@username) + '%'
ORDER BY username
Select username,user_id,user_type
from db2.users
where username like '%' + TRIM(@username) + '%'
ORDER BY username
Select username,user_id,user_type
from db3.users
where username like '%' + TRIM(@username) + '%'
ORDER BY username
Select username,user_id,user_type
from db4.users
where username like '%' + TRIM(@username) + '%'
ORDER BY username
Select username,user_id,user_type
from db5.users
where username like '%' + TRIM(@username) + '%'
ORDER BY username
The code that I am using to try and run this procedure and then append it to the list are as follows:
def user_query(user, conn, output_field):
global user
user_results = []
username = user.get()
cursor = conn.cursor()
get_user_stored_proc = "SET NOCOUNT ON; EXEC [dbo].[getUser] @username = ?"
output_field.config(state=NORMAL)
output_field.delete('1.0', END)
cursor.execute(get_user_stored_proc, username)
#TODO Fix this so that it will output everything from the query
columns = [column[0] for column in cursor.description]
for row in cursor:
user_results.append(dict(zip(columns, row)))
print_results(user_results, output_field)
#cursor.close()
#conn.close()
As previously mentioned, the only output I have returned to me when running this is the result of the first query. Any help is appreciated!