I wrote this code to delete duplicates from a table. It works fine when executed in Microsoft SQL Server Management Studio but I can't get it to work executing with Python.
There is no error occuring, it's just not working ... I tried executing other queries aswell without any problems.
Someone an idea what could be wrong ? I'm using Python 2.7
import pymssql
import time
conn = pymssql.connect(server='rfhete755', database='EEX')
c = conn.cursor()
p = """
SELECT [ID]
,[Operator]
,[Source]
,[Timestamp]
,ROW_NUMBER() OVER (
PARTITION BY [Operator]
,[Source]
,[Timestamp] ORDER BY [Timestamp]
) AS Rnum
FROM [EEX].[dbo].[Wind_Solar];
WITH CTE
AS (
SELECT [Operator]
,[Source]
,[Timestamp]
,ROW_NUMBER() OVER (
PARTITION BY [Operator]
,[Source]
,[Timestamp] ORDER BY [Timestamp]
) AS Rnum
FROM [EEX].[dbo].[Wind_Solar]
)
DELETE
FROM CTE
WHERE Rnum <> 1"""
print p
c.execute(p)
time.sleep(2)
conn.commit()
time.sleep(1)
c.close()
conn.close()
\nescape sequence to encode those, and using a literal newline is a syntax error.