2017-06-02 101 views
-1
query = "INSERT INTO vcdata.vc_staging " 
query += "(Offer_UOID, Offer_pgURL, Offer_URL, Product_Brand, Date_Identification, " 
query += "Date_Publication, Product_Category, Product_Title, Offer_Id, " 
query += "Seller_name, Seller_id, Seller_country, Seller_type, Price_ResaleEUR, " 
query += "Price_ResaleUSD, Product_Material, Product_Color, Product_Condition, " 
query += "Product_Dimension, Product_Width, Product_Height, Product_Depth, Wish_hits, " 
query += "Seller_Comments, Seller_Account, Seller_Count_of_Followers, Seller_Count_of_Following, " 
query += "Offer_Likes, Date_Sold, Buyer_Id, Price_Declared_EUR, Buyer_Name, Buyer_Account, " 
query += "Buyer_Country, Buyer_Type, Offer_Visibility, Offer_Status, Domain, Price_EstRetail, " 
query += "Product_SN, SN_comments, Product_Condition2, Offer_View_Hits, Offer_Cart_Hits, Date_Release, " 
query += "Price_Local, Currency, Seller_Address, Seller_Facebook, Product_Length, Price_Declared_Local) " 
query += "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " 
query += "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " 
query += "?, ?, ?, ?, ?) " 
query += "ON DUPLICATE KEY UPDATE SET Date_Last_Modified='%s', Offer_Visibility ='%s', " 
query += "Date_Release='%s'" 

错误:SQL服务器上使用重复的查询更新蟒蛇

ERROR:[SQL Server]Incorrect syntax near the keyword 'ON'. (156)

回答

0

这不会解决你的问题,但它给你一个提示代码:

query = """INSERT INTO vcdata.vc_staging 
      (Offer_UOID, Offer_pgURL, Offer_URL, Product_Brand, Date_Identification, 

      .... MORE LINES ... 

      ON DUPLICATE KEY UPDATE SET Date_Last_Modified='%s', Offer_Visibility ='%s', 
      Date_Release='%s' 
     """ 

它会帮助您复制/将查询粘贴到SQL查询执行程序中

1

[1] SQL Server不接受以下语法:INSERT ...ON DUPLICATE KEY UPDATE SET

[2]而不是INSERT ... SELECT ... ON DUPLICATE KEY UPDATE SET(这是 - 我相信 - MySQL的句法),我会用:

[2.1]

MERGE dbo.Target 
USING dbo.Source ON Target.id = Source.id 
WHEN MATCHED THEN UPDATE SET ... 
WHEN NOT MATCHED THEN INSERT(...) VALUES(...) 

记住,有与MERGE声明的一些问题,问题描述为here

或[2.2] INSERT ... SELECT ... WHERE NOT EXISTS (...) + UPDATE ... SET ... FROM dbo.Target a INNER JOIN dbo.Source b ON ... WHERE EXISTS (...)