使用多个值组合更新单个记录 [英] update single record with multiple values combination

查看:54
本文介绍了使用多个值组合更新单个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



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屋!

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