1

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

1 Answer 1

1

Try this one:

query = f"EXEC [dbo].[kpi_init] '{kpi}'"
cursor.execute(query)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.