Reputation: 303
I recently decided to migrate some of my scripts from jupyter notebook to plain old python scripts (.py) for several reasons. in jupyter, everything works properly, however the same code doesn't do anything in SQL. I know the procedure is correct because if I run it directly on the server, it does the trick.
my code is:
query = 'EXEC [dbo].[kpi_init] '+kpi+';'
cursor.execute(query)
I tried adding quotes, like this, no success:
query = 'EXEC [dbo].[kpi_init] \''+kpi+'\';'
I tried using parameterised queries, like this, no success:
query = 'EXEC [dbo].[kpi_init] ?;'
cursor.execute(query, [kpi])
worth mentiong that kpi is a simple variable containing something like A00 or X23 and it's there, as I can print it out and use it to trigger external functions. it's only my SQL code that doesn't work. am I missing something?
thanks
Upvotes: 1
Views: 31
Reputation: 9494
Try this one:
query = f"EXEC [dbo].[kpi_init] '{kpi}'"
cursor.execute(query)
Upvotes: 1