메뉴 건너뛰기

tnt_db

MS-SQL mssql update예제(select ~ update)

구퍼 2008.10.31 10:21 조회 수 : 6115

update to_userauth
set user_id = b.new_id
from to_userauth, (
select distinct a.user_id ori_id, c.user_id new_id
from hscity.dbo.to_user a, to_userauth b, to_user c
where a.user_id=b.user_id
) b
where to_userauth.user_id=b.ori_id

update하는것은 to_userauth의 user_id가 되면 출처는 inline query인 b에서 나오는 값으로 update한다.
이때 받아들이는 곳(to_userauth)는 alias를 쓰면 안되고 위에서와 같이 테이블명을 바로 사용해야 오류가발생하지 않으며..
(여러 부분으로 구성된 식별자 ""은(는) 바인딩할 수 없습니다. ...라는 오류가 발생함)
출처가 되는 곳은 inline query를 사용하여 alias를 부여해서 사용해도 됨.
위로