I have a query with multiple parameters that I need to run using pyodbc and I have an issue. This is a simplified version of the query, with only one parameter (I actually have 6)
declare @alertTypeName nvarchar(255)
set @alertTypeName = ?
SELECT TOP 1 Id FROM AlertType WHERE Name = @alertTypeName
@alertTypeName can have special characters, for example 'Boli şi Dăunători'.
Naturally, if I were to run this query directly in SQL Server I would set @alertTypeName = N'Boli şi Dăunători'. The SELECT does not return anything without adding N in front of the text.
My problem is, how do I send the value as parameter to the query in cursor.execute() so it will be correctly encoded?
This is python my code at the moment (simplified version):
query = textwrap.dedent("""
declare @alertTypeName nvarchar(255)
set @alertTypeName = ?
SELECT TOP 1 Id FROM AlertType WHERE Name = @alertTypeName
""")
[...]
alertTypeName = "Boli şi Dăunători"
[...]
paramValues = [syswinAlertId, code, alertTypeName, alertMessage, createdBy, modifiedBy]
cursor.execute(query, paramValues)
alertTypeName can have different values depending on some conditions, so I cannot just add it directly to the query text.