Here is the SQL:
CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int)
INSERT INTO dbo.TmpFeesToRules1(Name, LookupId)
SELECT DISTINCT Name, 0 FROM Lending.Fee
UNION SELECT DISTINCT Name, 0 FROM Lending.ApplicationFee
INSERT INTO dbo.tblLookup (LookupType, LookupCode, LookupDesc, EditFlag, DeletedFlag, DefaultFlag)
SELECT 'FEE_CODE', Name, Name, 0, 0, 0
FROM dbo.TmpFeesToRules1
UPDATE dbo.TmpFeesToRules1
SET
LookupId = L.LookupID
FROM
dbo.tblLookup L
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = L.LookupDesc
WHERE
L.LookupType = 'FEE_CODE'
CREATE TABLE dbo.TmpFeesToRules2(FeeId int, Name varchar)
INSERT INTO dbo.TmpFeesToRules2(FeeId, Name)
SELECT FeeId, Name FROM Lending.ApplicationFee
GO
UPDATE Lending.ApplicationFee
SET Lending.ApplicationFee.FeeTypeId = T.LookupId
FROM dbo.TmpFeesToRules2 TT
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = TT.Name
WHERE Lending.ApplicationFee.FeeId = TT.FeeId
DROP TABLE dbo.TmpFeesToRules1
DROP TABLE dbo.TmpFeesToRules2
Here is the error:
Invalid object name 'dbo.TmpFeesToRules2'.
Execute failed, return code: 1
Any ideas?