0
嘗試將tempTable中的行添加到表時遇到問題。問題是它添加了TempDealer表中的行,即使它們已經在Dealership表中(請注意,我在WHERE語句中指定WHERE td.supplier_ref NOT IN(SELECT supplier_ref FROM @dealerStatus)。每當我運行?。該存儲過程是從TempDealer到經銷商表再所有行增加時,它僅應提前加入他們,一旦任何想法感謝從臨時表導入SQL
INSERT INTO @dealerStatus (dealerId, supplier_ref, [add], [timestamp])
SELECT NULL, td.supplier_ref, 1, GETDATE()
FROM TempDealer td
WHERE td.supplier_ref NOT IN (SELECT supplier_ref FROM @dealerStatus)
INSERT INTO Dealership(
dealership_name,
telephone,
fax,
sales_email,
support_email,
service_mask,
address1,
address2,
town,
county,
postcode,
website,
date_modified,
supplier_ref,
dealer_type,
county_id,
town_id,
area_id,
district_id,
longitude,
latitude
)
SELECT DISTINCT
[updateSource].leasing_broker_name,
[updateSource].telephone,
[updateSource].fax_number,
[updateSource].email,
[updateSource].support_email,
[updateSource].service_mask,
[updateSource].address1,
[updateSource].address2,
[updateSource].town,
[updateSource].county,
[updateSource].post_code,
[updateSource].web_address,
GETDATE(),
[updateSource].supplier_ref,
1,
[updateSource].county_id,
[updateSource].town_id,
[updateSource].region,
[updateSource].district,
[updateSource].longitude,
[updateSource].latitude
FROM
@dealerStatus dealerUpdateStatus INNER JOIN
TempDealer [updateSource] ON dealerUpdateStatus.supplier_ref = updateSource.supplier_ref
WHERE
dealerUpdateStatus.[add] = 1
現在你說「插入到經銷商狀態每一行從TempDealer沒有一個供應商參考匹配已經在(在)dealerStatus」那裏的問題。是當它檢查這個時,(在)dealerStatus是空的。我想,您需要將您的WHERE子句更改爲NOT IN(SELECT supplier_ref FROM Dealership)。 –
我做了,它沒有插入任何東西WHERE td.supplier_ref NOT IN(SELECT supplier_ref FROM Dealership)。嚴重的是這讓我發瘋,它不會那麼複雜 – Tofetopo
很難弄清楚它有什麼問題,因爲顯然我不是那個看桌子的人,但讓我仔細看看。 –