2021年3月29日星期一

Pymssql: Incorrect syntax error while creating a table

So I'm trying to run a large query using pymssql like this (just writing 3 of the lines of the actual 100 line query) -

import pymssql    connection = pymssql.connect(server=rds_host, user=username, password=password, database='My_Database')  connection.autocommit(True)  crsr = connection.cursor()    sql_text = """       CREATE INDEX idx_t_site4 ON dbo1.Table1(SiteId) INCLUDE (ProductName, ProductID)       CREATE TABLE #t2 (SampleID INT);       SET @msg=dbo.addtimestamp('Setting Products...');RAISERROR(@msg, 0, 1) WITH NOWAIT;    """    crsr.execute(sql_text)  connection.commit()  

However, I get the following error -

pymssql.ProgrammingError: (102, b"Incorrect syntax near '#t2'.DB-Lib error message 20018,  severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")  

I even tried removing paranthesis around SampleID INT, and also tried using [] around it, but it did not work.

https://stackoverflow.com/questions/66863523/pymssql-incorrect-syntax-error-while-creating-a-table March 30, 2021 at 09:05AM

没有评论:

发表评论