Thursday, September 9, 2010

SQL Server: Update Records

DECLARE @B_RID NVARCHAR(15);
DECLARE @B_LOC NVARCHAR(50);
DECLARE @B_NAME NVARCHAR(100);
DECLARE @AM_LOC NVARCHAR(50);
DECLARE @AM_NAME NVARCHAR(100);
DECLARE C1 CURSOR FOR
SELECT BASE.ROW_ID, BASE.LOC, BASE.NAME, AUTO.ACCOUNT_ID, AUTO.ACCOUNT_NAME FROM S_ORG_EXT BASE, UCM_ACCT_POST_AUTO_MATCH AUTO
WHERE BASE.LOC = AUTO.ACCOUNT_ID AND BASE.LOC IN (
SELECT DISTINCT ORG_ACCNT_LOC FROM EIM_FN_CIF_SYST WHERE IF_ROW_STAT = 'PARTIALLY_IMPORTED')
ORDER BY BASE.LOC;
OPEN C1;
FETCH NEXT FROM C1 INTO @B_RID, @B_LOC, @B_NAME, @AM_LOC, @AM_NAME
WHILE @@FETCH_STATUS = 0
BEGIN
    UPDATE S_ORG_EXT SET NAME = @AM_NAME WHERE ROW_ID = @B_RID
    FETCH NEXT FROM C1 INTO @B_RID, @B_LOC, @B_NAME, @AM_LOC, @AM_NAME
END
CLOSE C1
DEALLOCATE C1

No comments: