Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Refactor OwnerID - Step 2
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