我有2个表A和B.我需要在表A上运行更新,但是从表B中的一个字段获取一个值以分配给表A中的一个字段,
代码如下:
Update [A]
set A.Code = 10,
A.Name = 'Test',
A.Link = (Select Link from [B] where [B].ID = 10)
from [A]
问题是,A.Link中的值总是空的!!!!
知道什么是错的
谢谢,
答案 0 :(得分:4)
A.Code = B.ID?如果是的话......
UPDATE A
SET A.LINK = B.LINK
,A.NAME = 'TEST'
FROM
TABLE_A A
INNER JOIN TABLE_B B
ON A.CODE = B.ID
答案 1 :(得分:0)
试试这个:
Update [A]
set A.Code = 10,
A.Name = 'Test',
A.Link = ISNULL((Select Link from [B] where [B].ID = 10),'it was null')
from [A]
SELECT * FROM [A] WHERE Name = 'Test'
链接列中是否有自定义it was null
消息?