본문 바로가기
MS-SQL

[MS-SQL 2008] MERGE 구문을 이용하여 INSERT 및 UPDATE

by Hwoarang757 2015. 8. 12.

                        

                         MERGE TARGET AS TARGET

                         USING TARGET_TEMP AS S

                         ON (

                                          TARGET.BALJPNO = S.KEY1

                                          AND

                                          TARGET.BALSEQ = S.KEY2

                                  )

-- 일치시 UPDATE

                         WHEN MATCHED THEN

                                  UPDATE SET

                                           

                                                  IOT = S. IOT

                       -- 미 일치시 INSERT

                         WHEN NOT MATCHED THEN

                                  INSERT

                                  (

                                          IOT

                                  )

                                  VALUES

                                  (

                                          S.IOT

                                  ) ;