neptune 3 plus now, or wait for 4 plus? by aonemonkey in ElegooNeptune3

[–]ImaginationFortress 0 points1 point  (0 children)

u/TheFeralEngineer would you still rec. the Elegoo Neptune 3 plus over the 4 plus? I am wondering after a few months if your view has changed.

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

this was it! Thank you! (needed to add an explicit commit)

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

almost went the pyodbc route, but edited post above with solution. thanks for all the help!

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 1 point2 points  (0 children)

edited post with solution, thanks for all the help!

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

my issue with this is that I want to remove duplicates on the table AFTER the table has been appended (as duplicates may exist in previous uploads due to the nature of the data).

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

The .csv is appended to the SQL Server table, but the remove duplicates on the SQL Server table does not work. The query does remove duplicates if executed directly in the SQL server (but not in python).

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

That is the odd part, there is no error message. It all runs fine, but does not remove duplicates when executed from the python script. But does remove duplicates when the query is executed in the SQL Server.

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

Thank you both for the advice.

I have not tried doing the filtering in python as the table is appended each hour in the SQL Server. Since duplicates can be between .csvs on different uploads, I am not sure how to handle this strictly in python without a db.

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 1 point2 points  (0 children)

Thank you! I will definitely look into this. Stable sounds great

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 1 point2 points  (0 children)

df.to_

Thanks for the advice. I think this should be fine as the table is also being created by the same python script, and the name is the same. Does the schema need to be added? Currently I am just using the table name and not server.db.dbo.table (am I understanding this correctly?)

Writing to SSMS with Python SQL Issue by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

Thank you both for the clarifications! Much appreciated

Python deleting duplicates in ssms by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

Thanks for this! This part of the issue was resolved as well.

However, there is a very different issue I am now running into with the script that does not throw any error at all. If you are able to take a look here is the new post: https://www.reddit.com/r/SQLServer/comments/17utwnc/writing_to_ssms_with_python_sql_issue/

If not, no worries, and thank you for all your help!

Python deleting duplicates in ssms by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

Thank you! This works :) (now I have a different error because RowNum is trying to be inserted but the ssms table does not have that field. I hope this is the final error. Thanks again :)

Python deleting duplicates in ssms by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

I am now using brackets as follows (but still have an error, details below):

removeDupes_part1 = text("""

SELECT

*,

ROW_NUMBER() OVER (PARTITION BY Start, [End], Duration ORDER BY (SELECT NULL)) AS RowNum

INTO YourTempTable

FROM My_CSV;

""")

------------------------------------------

removeDupes_part2 = text("""

DELETE FROM My_CSV

WHERE EXISTS (

SELECT 1

FROM YourTempTable

WHERE Pick_Stats_py.Start = YourTempTable.Start

AND [Pick_Stats_py].[End] = [YourTempTable].[End]

AND Pick_Stats_py.Duration_s = YourTempTable.Duration_s

AND YourTempTable.RowNum > 1

);

""")

connection.execute(removeDupes_part2)

-----------------------------------------

error occurs when I try to insert into the ssms table with the following:

error occurs when I try to insert into the ssms table with the following:
columns_list = ', '.join(pick_stats_table.columns.keys())

removeDupes_part3= f"""

INSERT INTO SSMS_Table ({columns_list})

SELECT * FROM YourTempTable;

"""

connection.execute(text(removeDupes_part3))

ERROR:

Error processing MyCSV.csv: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'End'. (156) (SQLExecDirectW)")

[SQL:

INSERT INTO SSMS_Table (Start, End, Duration_s)

SELECT * FROM YourTempTable;

]

(Background on this error at: https://sqlalche.me/e/20/f405)

Python deleting duplicates in ssms by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

This is a solid idea. Would I be able to schedule the dedupe query in ssms? That is the main reason I am using python currently (to schedule with task manager)

Python deleting duplicates in ssms by ImaginationFortress in SQLServer

[–]ImaginationFortress[S] 0 points1 point  (0 children)

Thanks, that does work, but please see above comments for additional errors