ousoonerjoe
Programmer
Due to legacy code, the date fields have to be set to NULL rather than use a default value (such as 1/1/1900). As a result, a trigger is used to insure that any default values are converted back to NULL.
Is there a more efficient approach to this?
--------------------------------------------------
Bluto: What? Over? Did you say "over"? Nothing is over until we decide it is! Was it over when the Germans bombed Pearl Harbor? No!
Otter: Germans?
Boon: Forget it, he's rolling.
--------------------------------------------------
Is there a more efficient approach to this?
Code:
ALTER TRIGGER [dbo].[trg_Tmpwpmas_DateNulls]
ON [dbo].[tmpwpmas]
FOR INSERT, UPDATE
AS
UPDATE Tmpwpmas
SET ModifiedBy = HOST_NAME(),
ModifyDate = GETDATE()
FROM Tmpwpmas d
INNER JOIN Inserted i on d.id_num = i.id_num;
UPDATE Tmpwpmas
SET wpmas_dt_billed = NULL
FROM Tmpwpmas d
INNER JOIN Inserted i on d.id_num = i.id_num
WHERE i.wpmas_dt_billed = '1/1/1900';
UPDATE Tmpwpmas
SET wpmas_dt_complet = NULL
FROM Tmpwpmas d
INNER JOIN Inserted i on d.id_num = i.id_num
WHERE i.wpmas_dt_complet = '1/1/1900';
UPDATE Tmpwpmas
SET wpmas_dt_pickup = NULL
FROM Tmpwpmas d
INNER JOIN Inserted i on d.id_num = i.id_num
WHERE i.wpmas_dt_pickup = '1/1/1900';
UPDATE Tmpwpmas
SET wpmas_dt_schrtn = NULL
FROM Tmpwpmas d
INNER JOIN Inserted i on d.id_num = i.id_num
WHERE i.wpmas_dt_schrtn = '1/1/1900';
UPDATE Tmpwpmas
SET wpmas_dt_shipped = NULL
FROM Tmpwpmas d
INNER JOIN Inserted i on d.id_num = i.id_num
WHERE i.wpmas_dt_shipped = '1/1/1900';
UPDATE Tmpwpmas
SET wpmas_dt_started = NULL
FROM Tmpwpmas d
INNER JOIN Inserted i on d.id_num = i.id_num
WHERE i.wpmas_dt_started = '1/1/1900';
--------------------------------------------------
Bluto: What? Over? Did you say "over"? Nothing is over until we decide it is! Was it over when the Germans bombed Pearl Harbor? No!
Otter: Germans?
Boon: Forget it, he's rolling.
--------------------------------------------------