0

I am trying to execute below SQL query by introducing 2 variables in Python but getting error,

Original Query:

ALTER DATABASE db1 MODIFY (SERVICE_OBJECTIVE = 'DW300');

I want to use variables for db1 and 'DW300'. I have tried below statement in Python and got error.

dwu = 'DW100'
sqlpool = 'db1'
cursor.execute("""ALTER DATABASE ? MODIFY (SERVICE_OBJECTIVE = ?) """, (sqlpool, dwu))

Error: pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '@P1'. (102) (SQLExecDirectW)")
0

1 Answer 1

1

I use sqlite and it accepts this answe.

try the use of fstrings

f"""Alter Database {sqlpool} modify (service objective = {dwu}) """
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.