I am working on a consolidated SQL script that needs to
- Add a datetime column named AdjudicatedDateTime to the WarrantyAdjudicationStaging table.
- Add a default date of GETDATE() for new entries into the table
- Update old records with NULL values of the AdjudicatedDateTime
The statements seem to run fine alone, but I need them to run together.When I attempt to run them together I get the following error:
Msg 207, Level 16, State 1, Line 27
Invalid column name 'AdjudicatedDateTime'
USE NATesterData
ALTER TABLE WarrantyAdjudicationStaging
ADD AdjudicatedDateTime datetime
USE NATesterData
ALTER TABLE WarrantyAdjudicationStaging
ADD CONSTRAINT DF_WarrantyAdjudicationStaging DEFAULT GETDATE() FOR AdjudicatedDateTime
USE NATesterData
UPDATE WarrantyAdjudicationStaging
SET AdjudicatedDateTime = AuditResults.AdjudicatedDateTime
FROM WarrantyAdjudicationStaging was
INNER JOIN
(
SELECT MAX(dateTimeRun) AdjudicatedDateTime, was.WarrantyAdjudicationGroupID
FROM WarrantyAdjudicationStaging was
INNER JOIN (
SELECT DISTINCT WarrantyAdjudicationGroupID
FROM WarrantyAdjudicationStaging
WHERE WarrantyAuditKey IS NULL
) exceptions
ON was.WarrantyAdjudicationGroupID = exceptions.WarrantyAdjudicationGroupID
INNER JOIN WarrantyUsageAudit wua
ON was.WarrantyAuditKey= wua.WarrantyAuditKey
GROUP BY was.WarrantyAdjudicationGroupID
) AuditResults on was.WarrantyAdjudicationGroupID = AuditResults.WarrantyAdjudicationGroupID
WHERE WAS.AdjudicatedDateTime IS NULL
AND WarrantyAuditKey IS NULL
USEstatements, when they are define the same database?