-- base oracle
UPDATE (
select cu.stat as stat
, cs.sys_date as last_update_date
, cu.user_id as user_id
, cu.sys_date as update_date
from table_1 cs
, table_2 cu
where cs.emp_sabun = cu.user_id
)
SET STAT = 'N'
, update_date = to_char(sysdate, 'yyyymmdd')
where user_id IN (
select distinct expired_user
from table_a
where trunc(expired_date) = trunc(sysdate)
and SYSTEM_NAME IN ('xxxxxx','yyyyyy')
AND MAIL_FLAG = 'Y'
)
and last_update_date < trunc(sysdate -7)
-- to mssql
IF OBJECT_ID('tempdb..#TEMP1') IS NOT NULL
BEGIN
DROP TABLE #TEMP1
END
CREATE TABLE #TEMP1
(
[INDEX] [INT] NOT NULL IDENTITY(1,1),
[MASTERID1] [VARCHAR](20) NOT NULL
);
INSERT INTO #TEMP1 VALUES ('KKK1-1');
INSERT INTO #TEMP1 VALUES ('KKK1-2');
IF OBJECT_ID('tempdb..#TEMP2') IS NOT NULL
BEGIN
DROP TABLE #TEMP2
END
CREATE TABLE #TEMP2
(
[INDEX] [INT] NOT NULL IDENTITY(1,1),
[MASTERID2] [VARCHAR](20) NOT NULL
);
INSERT INTO #TEMP2 VALUES ('KKK2-1');
INSERT INTO #TEMP2 VALUES ('KKK2-2');
UPDATE T1
SET T1.MASTERID1 = 'OOO'
FROM #TEMP1 T1 JOIN #TEMP2 T2
ON T1.[INDEX] = T2.[INDEX]
WHERE T1.[INDEX] = 1
UPDATE T2
SET T2.MASTERID2 = '111'
FROM #TEMP1 T1 JOIN #TEMP2 T2
ON T1.[INDEX] = T2.[INDEX]
WHERE T1.[INDEX] = 1
SELECT * FROM #TEMP1
SELECT * FROM #TEMP2