根据不同表中的字段是否相等插入是或否值 [英] inserting yes or no values based on fields in different tables being equal

查看:87
本文介绍了根据不同表中的字段是否相等插入是或否值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为LeadInventor的字段,

I have a field created titled LeadInventor,

如果第一个发明人表中的名称与发明人表匹配,我想让SQL Server做的是在LeadInventor字段中插入yes.第一个inventor表的名称作为一个字段,inventor表的名称首先和最后一个分开

what I want SQL Server to do is insert yes into the LeadInventor field if the names from the first inventor table match the inventor table. The first inventor table has the names as one field, the inventor table has them separated first and last

这是我到目前为止的编码,我知道这是错误的.

this is the coding I have so far, which I know is wrong.

if inventor.InventorFirst + ' ' +inventor.InventorLast  = firstinventor.firstinventorname
insert into Inventor(LeadInventor) values ('Yes')
else insert into Inventor(leadinventor) values ('No');

我想知道如何修复或重写它,以便它可以执行我要求的操作?

What I would like to know is how do I fix it, or re-write it so that it will do what I ask it to?

推荐答案

像这样吗?

UPDATE i
SET LeadInventor = 
    CASE 
        WHEN fi.FirstInventorName IS NULL THEN 'No' 
        ELSE 'Yes' 
    END
FROM Inventor i
    LEFT JOIN FirstInventor fi
    ON i.InventorFirst + ' ' + i.InventorLast = fi.FirstInventorName

这篇关于根据不同表中的字段是否相等插入是或否值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆