[Python] In python delete some rows from SQL query for a certain range of date (min & max) and...

Discussão em 'Python' iniciado por Stack, Fevereiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    When trying to execute this :

    mindate = min(df['review_ds'])
    maxdate = max(df['review_ds'])

    Unique_queue_id= df['queue id'].unique().astype(str).tolist()

    cnxn.execute(r"""DELETE FROM [DATAWRHS-FACEBOOK].[dbo].[QA_PDO_AGE_AFFINITY_NEW] WHERE [review_ds] >= '""" + str(mindate) + """'
    AND [review_ds] <= '""" + str(maxdate) + """'
    AND [queue id] IN Unique_queue_id
    """)
    cnxn.commit()


    I get this error


    ProgrammingError: ('42000', "[42000] [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'Unique_queue_id'. (102) (SQLExecDirectW)")
    ​

    Could someone please help knowing that I have mindate, maxdate and list of queue_ids.

    I want to update some data in SQL query, that has the same dates, and queues ids of a new received data. So I want to locate the data with (min and max dates, and select only for the queue ids that I have in my new data ) then delete and append the new data to the query.

    Continue reading...

Compartilhe esta Página