pertama buat table temporary untuk menyimpan ID yang unik atau sama.
SELECT
PFN_ID
into temp_table
FROM
PFM_TEMP_PENILAIAN
GROUP BY
PFN_ID
HAVING
COUNT (pfn_id) > 1
setelah itu lanjut dengan script di bawah ini
SELECT a.PFN_ID,b.NIP,'PFN-' + RIGHT (
'z0000000000000' + CONVERT (
VARCHAR (30),
(
(
SELECT
dbo.nvl (
CAST (
dbo.substr (MAX(PFN_ID), 5, 6) AS INTEGER
),
0
)
FROM
PFM_TEMP_PENILAIAN
) + (
row_number () OVER (ORDER BY a.PFN_ID)
)
)
),
6
) AS PFN_ID_BARU INTO temp_table2 from temp_table AS a LEFT JOIN PFM_TEMP_PENILAIAN AS b ON a.PFN_ID=b.PFN_ID
Sekarang update ID baru.
UPDATE T
SET t.PFN_ID = r.PFN_ID_BARU
FROM
PFM_TEMP_PENILAIAN AS T
LEFT JOIN temp_table2 AS r ON T.NIP = r.NIP
AND T.PFN_ID = r.PFN_ID
WHERE
r.PFN_ID IS NOT NULL
Selasa, 31 Juli 2018
Langganan:
Postingan (Atom)