2017-06-02 82 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 (...)