我有两个具有相同列的表
tbl_source (ID, Title) tbl_dest (ID, Title)
我想从tbl_source更新tbl_dest标题,其中dest和source中的id匹配.但是,如果源标题为null(或空白),我不想更新dest标题.
我有这个:
UPDATE tbl_dest SET tbl_dest.Title = (SELECT title FROM tbl_source WHERE tbl_dest.id = tbl_source.ID and tbl_source.title is not null)
但它继续插入空值.
我该如何构建这样的查询?
我正在使用SQL Server 2005.
谢谢.
使用内部联接......
Update tbl_dest Set tbl_dest.Title = tbl_source.Title From tbl_dest inner join tbl_source on tbl_dest.ID = tbl_source.ID Where tbl_source.Title is not null and tbl_source.Title <> ''