I have MSSQL stored procedure that takes 1 input parameter. When I execute it in SQL client it returns a set of rows and columns:
+-------------+----------+
| text| dt|
+-------------+----------+
|Sample Text 1|2019-01-01|
|Sample Text 2|2019-03-01|
|Sample Text 3|2019-06-01|
|Sample Text 4|2019-02-01|
+-------------+----------+
I tried to simulate the same behavior using pyodbc but none of the solutions I found worked.
I tried this code and many of its variations:
cnxn = pyodbc.connect(f'DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={host};DATABASE={db};UID={user};PWD={password}')
sql = """\
SET NOCOUNT ON;
DECLARE @return_value nvarchar(max);
EXEC @return_value = [dbo].[procname] 'someInputParam';
SELECT 'Return Value' = @return_value;
"""
crsr = cnxn.execute(sql)
data = crsr.fetchall()
print(data)
crsr.nextset()
data = crsr.fetchall()
print(data)
which returns
[]
[('0', )]
Is there any way I can extract data from both columns using pyodbc?