Created
February 4, 2021 19:03
-
-
Save BrianMRO/2bb0b9567d29a2821b2cf9508395b4a9 to your computer and use it in GitHub Desktop.
Refactor OwnerID - Step 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE [MyDatabase] | |
GO | |
SET ANSI_NULLS ON | |
GO | |
SET QUOTED_IDENTIFIER ON | |
GO | |
IF COL_LENGTH('dbo.XXMyTable', 'OwnerID') IS NOT NULL AND COL_LENGTH('dbo.XXMyTable', 'OldOwnerID') IS NOT NULL | |
BEGIN | |
UPDATE [XXMyTable] SET | |
[XXMyTable].[OwnerID] = | |
(SELECT [Contact].ContactID FROM [Contact] WHERE [Contact].[CompanyID] = [XXMyTable].[CompanyID] AND [UserID] = [XXMyTable].[OldOwnerID]) | |
WHERE [XXMyTable].[OldOwnerID] IS NOT NULL | |
END | |
IF COL_LENGTH('dbo.XXMyTable', 'ProductManagerID') IS NOT NULL AND COL_LENGTH('dbo.XXMyTable', 'OldProductManagerID') IS NOT NULL | |
BEGIN | |
UPDATE [XXMyTable] SET | |
[XXMyTable].[ProductManagerID] = | |
(SELECT [Contact].ContactID FROM [Contact] WHERE [Contact].[CompanyID] = [XXMyTable].[CompanyID] AND [UserID] = [XXMyTable].[OldProductManagerID]) | |
WHERE [XXMyTable].[OldProductManagerID] IS NOT NULL | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment