两个表在查找后将列设置为无产品

时间:2013-03-27 16:55:17

标签: tsql sql-update set

我有两个包含多列的表。其中一个产品是产品。如果产品不在table1上,那么make product =' noproduct'。有人可以帮我解决这个问题。表1列名称,地址,产品 table2列产品 如果产品不在表2中,那么产品='没有产品'

2 个答案:

答案 0 :(得分:0)

听起来你在谈论左连接。如果答案为空,则可以使用coalesce表达式返回自定义文本。

请参阅: http://msdn.microsoft.com/en-us/library/ms190349.aspx

答案 1 :(得分:0)

希望这会有所帮助:

update table1 set product  = ISNULL(table2.product , 'no product') from
table1 left join table2 on table1.product  = table2.product