使用多个值组合更新单个记录 [英] update single record with multiple values combination
问题描述
大家好,
i需要使用两张桌子
1.custmer
2.dcustomer
并将数据加载到与ncustnum连接的笔记表中,我遇到了多个reocords组合的问题我正在尝试下面一个
选择c。 nacct
note = case when(存在(从客户a中选择1,其中a.ncustnum = b.ncustnum和a.dece =''x''和a.rectype =''0'')并存在(从客户a中选择1,其中a.ncustnum = b.ncustnum和a.dece =''x''和a.rectype in(''''',''7''))然后''两者''当(存在(从客户a中选择1,其中a.ncustnum = b.ncustnum和a.dece =''x''和a.rectype =''0'')然后''primary''当(存在(从客户a中选择1,其中a.ncustnum = b.ncustnum和a.dece =''x''和a.rectype in(''''',''7'')然后''secondary''
来自dcustomer b加入客户c on b.ncustnum = c.ncustnum
工作正常但需要在声明时使用简单的情况进行更改。如果可能的话请发帖
谢谢,
试试这个
选择 b.ncustnum,c.nacct,
c.note
来自 dcustomer b 内部 加入
(选择 DISTINCT ncustnum,nacct,
CASE WHEN > rectype (' 6',' 7')那么 ' secondary' WHEN rectype = ' 0' THEN ' primary' ELSE ' both' END as note
FROM customer WHERE dece = ' x' 和 rectype in (' 6' ,' 7',' 0')) as c
on b.ncustnum = c.ncustnum
Hi all,
i need to use two tables
1.custmer
2.dcustomer
and load the data into note table join with ncustnum ,i am getting problem with multiple reocords combination i am trying bellow one
select c.nacct
note=case when (exists(select 1 from customer a where a.ncustnum=b.ncustnum and a.dece=''x'' and a.rectype=''0'') and exists(select 1 from customer a where a.ncustnum=b.ncustnum and a.dece=''x'' and a.rectype in(''6'',''7''))) then ''both'' when (exists(select 1 from customer a where a.ncustnum=b.ncustnum and a.dece=''x'' and a.rectype=''0'') then ''primary'' when (exists(select 1 from customer a where a.ncustnum=b.ncustnum and a.dece=''x'' and a.rectype in (''6'',''7'') then ''secondary''
from dcustomer b join customer c on b.ncustnum=c.ncustnum
its working fine but need to change using easy case when statement . if is it possible then please post
Thanks,解决方案Try this
select b.ncustnum, c.nacct, c.note from dcustomer b inner join (select DISTINCT ncustnum, nacct, CASE WHEN and rectype in('6','7') THEN 'secondary' WHEN rectype='0' THEN 'primary' ELSE 'both' END as note FROM customer WHERE dece='x' and rectype in('6','7','0')) as c on b.ncustnum=c.ncustnum
这篇关于使用多个值组合更新单个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!