ousoonerjoe
Programmer
I need a TRIGGER that can replace '1/1/1900' with NULL on INSERT or UPDATE. However, I have an issue with the fact that the table may or may not have a UNIQUE identifier. I threw together the following when the table does have a UniqueID, but not quite sure how to handle a table that does not have one.
Any assistance or direction you can offer would be highly appreciated.
thank you.
--------------------------------------------------
"...and did we give up when the Germans bombed Pearl Harbor? NO!"
"Don't stop him. He's roll'n."
--------------------------------------------------
Code:
CREATE TRIGGER [trg_DateTest_Nulls]
ON DateTest
FOR INSERT, UPDATE
AS
DECLARE @Date DATETIME
SET @Date = (SELECT StartDate FROM Inserted)
IF @Date = '1/1/1900'
UPDATE DateTest
SET StartDate = NULL
WHERE DateID = (SELECT DateID FROM Inserted)
SET @Date = (SELECT EndDate FROM Inserted)
IF @Date = '1/1/1900'
UPDATE DateTest
SET EndDate = NULL
WHERE DateID = (SELECT DateID FROM Inserted)
thank you.
--------------------------------------------------
"...and did we give up when the Germans bombed Pearl Harbor? NO!"
"Don't stop him. He's roll'n."
--------------------------------------------------