我有以下select语句。 我想将ContactAssociate的值从'Bob'更新为'Jane'。有可能这样做吗?
SELECT TOP (1500) ContactID, ContactNotes,
ContactAssociate, ContactAppointment
FROM
tb_Contact
WHERE
(ContactAssociate = 'Bob') AND
(ContactAppointment = 0)
答案 0 :(得分:5)
使用:
UPDATE TB_CONTACT
SET contactassociate = 'Jane'
WHERE contactassociate = 'Bob'
您提供的contactappointment
检查的查询为零 - 如果您想要包含该检查,则查询将为:
UPDATE TB_CONTACT
SET contactassociate = 'Jane'
WHERE contactassociate = 'Bob'
AND contactappointment = 0
UPDATE
语句不支持TOP
关键字,因此您的更新语句将为:
UPDATE TB_CONTACT
SET contactassociate = 'Jane'
WHERE contactid IN (SELECT TOP (1500)
contactid
FROM TB_CONTACT
WHERE contactassociate = 'Bob'
AND contactappointment = 0)
...但是这将提供随机联系 - 您应该在子查询中指定ORDER BY
子句以获得一致的结果。
参考:
答案 1 :(得分:1)