[MSSQL] UPDATE~SELECT 문의 사용

Database 2009.05.13 10:30 Posted by 애플자라

MSSQL ==> B 테이블 SELECT 한것을 A테이블에 업데이트 치기@_@;; 죽을뻔함

UPDATE A SET
A.CUSTOMER_KEY = B.MEMBER_ID,
A.SEND_DT = CONVERT(CHAR(8),B.DELIVER_TIME,112),
A.SEND_TM = REPLACE(CONVERT(VARCHAR(20),B.DELIVER_TIME,108),':',''),
A.ERROR_CD = B.ERROR_CODE
 from nvecaresendlog A, smsauto_list_03 B
where B.workday ='20090512'
and B.seqno='16'
AND A.CUSTOMER_KEY = B.MEMBER_ID

참고 - http://blog.naver.com/rainbow8830/70030692861

-- 다른유형
UPDATE A
 SET A.JobTitle = B.UserJobTitle
FROM BackDatabase.dbo.DATTACHINFO A, Appro.dbo.ATTACHINFO B
where A.DocID=B.DocID
and A.FileSN=B.FileSN 

 

update customer aa
set (home_address)= (select home_address from customer_temp where customer_id=aa.customer_id);