I have a pipe delimited text file with SQL queries. I am trying to loop through and execute each query. When I print the queries in the file in the loop, everything seems fine. If I copy the text and run in SSMS, the SQL runs fine, but when I try to execute with pyodbc, I get the error:
ProgrammingError: No results. Previous SQL was not a query.
Here is my code:
with open('C:/users/a/tria_file_by_ASLOB12.csv', 'r') as queryFile:
for line in queryFile:
fields = line.split('|')
print fields[0]
#cursor.execute(fields[0])
#cursor.fetchall()
Returns:
SELECT COUNT(DISTINCT(pol_num)) In_Force_Count, sum(lmt_pol_s) Exposure
FROM bapu.dbo.fact_prem
WHERE aslob = 90
and CONCAT(2016,1231) between CAST(d_pol_eff AS DATE) and CAST(d_pol_exp AS DATE)
and cvg_state = 'WA'
and rpt_co_name in (SELECT Ent_Name FROM NAIC_Legal_Ent_Lookup WHERE ID = 40045)
SELECT COUNT(DISTINCT(pol_num)) In_Force_Count, sum(lmt_pol_s) Exposure
FROM bapu.dbo.fact_prem
WHERE aslob = 90
and CONCAT(2016,1231) between CAST(d_pol_eff AS DATE) and CAST(d_pol_exp AS DATE)
and cvg_state = 'WI'
and rpt_co_name in (SELECT Ent_Name FROM NAIC_Legal_Ent_Lookup WHERE ID = 40045)
etc
What am I missing?
Thanks