UPDATE #temp
SET duty_count = (SELECT Count(*)
FROM duty_trak
WHERE driver_id = #temp.driver_id)
UPDATE #temp
SET vehicle_id = (SELECT vehicle_id
FROM duty_trak
WHERE driver_id = #temp.driver_id)
代替相等,我使用IN,ALL和Exists但不支持这些。如何删除此错误?
答案 0 :(得分:0)
我认为这可能更符合您的要求。它使用UPDATE FROM:
UPDATE tmp
SET
tmp.Duty_Count = dutr.Duty_Count
FROM
#Temp tmp
JOIN
(
SELECT
Driver_ID,
COUNT(*) AS Duty_Count
FROM
Duty_Trak
GROUP BY
Driver_ID
) dutr
ON (tmp.Driver_ID = dutr.Driver_ID)
UPDATE tmp
SET
tmp.VEHICLE_ID = dutr.VEHICLE_ID
FROM
#Temp tmp
JOIN
Duty_Trak dutr
ON (tmp.Driver_ID = dutr.Driver_ID)
答案 1 :(得分:0)
您是否只想使用一个值更新临时表,我猜您只能更新只有一个值的行,因此,只需在选择语句中使用“Top 1”...