select a.JAEHAEJA_RGNO ,
( select e.JAEHAEJA_RGNO
from nis..BAA130MT d
inner join nis..BAA010MT e
on e.WONBU_NO = d.WONBU_NO
where d.RGNO = a.JAEHAEJA_RGNO
) -- BAA010MT(업데이트할 주민번호 )
from ris..BGH020MT a
where exists ( select 1
from nis..BAA130MT b
where b.RGNO = a.JAEHAEJA_RGNO
group by a.JAEHAEJA_RGNO
having count(*) = 1
)
and exists ( select 1
from nis..BAA130MT d
inner join nis..BAA010MT e
on e.WONBU_NO = d.WONBU_NO
left outer join nis..BAA010MT c
on c.JAEHAEJA_RGNO = a.JAEHAEJA_RGNO
where c.JAEHAEJA_RGNO IS NULL --BAA010MT에 없는 주민번호
and d.RGNO = a.JAEHAEJA_RGNO
)
이 select 문을 update문으로 고칠려구 하는데요...ㅠㅠ 왜 안되는지 잘모르겠어요..ㅠㅠ
update ris..BGH020MT a
set a.JAEHAEJA_RGNO = ( select e.JAEHAEJA_RGNO
from nis..BAA130MT d
inner join nis..BAA010MT e
on e.WONBU_NO = d.WONBU_NO
where d.RGNO = a.JAEHAEJA_RGNO
)
where exists ( select 1
from nis..BAA130MT b
where b.RGNO = a.JAEHAEJA_RGNO
group by a.JAEHAEJA_RGNO
having count(*) = 1
)
and exists ( select 1
from nis..BAA130MT d
inner join nis..BAA010MT e
on e.WONBU_NO = d.WONBU_NO
left outer join nis..BAA010MT c
on c.JAEHAEJA_RGNO = a.JAEHAEJA_RGNO
where c.JAEHAEJA_RGNO IS NULL --BAA010MT에 없는 주민번호
and d.RGNO = a.JAEHAEJA_RGNO
)
이런식으로 고쳤는데 이러가 나네요...ㅠㅠ
에러 메시지는
Server Message: Number 102, Severity 15
Server 'SEOUL01_DEV', Line 1:
Incorrect syntax near 'a'.
Server Message: Number 102, Severity 15
Server 'SEOUL01_DEV', Line 2:
Incorrect syntax near '='.
Server Message: Number 107, Severity 15
Server 'SEOUL01_DEV', Line 3:
The column prefix '.e.' does not match with a table name or alias name used in the query. Either the table is not specified in the FROM clause or it has a correlation name which must be used instead.
Server Message: Number 156, Severity 15
Server 'SEOUL01_DEV', Line 13:
Incorrect syntax near the keyword 'and'.
Server Message: Number 107, Severity 15
Server 'SEOUL01_DEV', Line 17:
The column prefix 'a' does not match with a table name or alias name used in the query. Either the table is not specified in the FROM clause or it has a correlation name which must be used instead.
Server Message: Number 107, Severity 15
Server 'SEOUL01_DEV', Line 19:
The column prefix 'a' does not match with a table name or alias name used in the query. Either the table is not specified in the FROM clause or it has a correlation name which must be used instead.
이고구요 잘 부탁드립니다..ㅠㅠ
|