November 8, 2005 at 4:10 pm
Hello All,
The trigger has to do insert/update on a datetime column, but here is the caveat.
The milliseconds needs to be removed from the date: 2005-11-04T11:01:44.7930000-
Simply speaking the format should be like this: yyyy-mm-dd hh:mm:ss AM/PM
ON dbo.CompanyStations
FOR UPDATE
AS
BEGIN
IF UPDATE(LastUpdated)
UPDATE dbo.CompanyStations SET LastUpdated = CONVERT(GETDATE())
WHERE LastUpdated IN (SELECT bar FROM inserted)
END
GO
Thanks for your help!
Dave
November 8, 2005 at 4:22 pm
I hate triggers... almost as much as cursors.
But you can set the date column = convert( varchar(20), getdate(), 13)
November 8, 2005 at 5:24 pm
Why this hate for triggers?
November 8, 2005 at 11:29 pm
hi friend,
You seem to be familiar and thorough with triggers. I am new to SQL Server and i want to create trigger, such that whenever primary key column in 'first' table is updated, all other columns in other tables to be updated with the new values where old columns are equal. I can do it using 'on update cascade', but when there is cycle, i can not do it. i hope you can help me with this. And i'm not clear about 'inserted' and 'deleted' tables.
the example of what i want to do look like this..
CREATE TRIGGER dbo.updt
ON dbo.letters
FOR UPDATE
AS
BEGIN
IF UPDATE(letter_code)
update dbo.lett_off
set letter_code=inserted.letter_code
where lett_off.letter_code=deleted.letter_code
END
GO
November 9, 2005 at 1:12 pm
Simple answer: They are, 99% of the time, used, written, designed, and implemented incorrectly, improperly, etc.
Or put another way, they are the frequent path/tool of those not properly designing an application.
I hate them less than cursors because, unlike cursors, there are proper times and places for them--though so very rare and far between.
November 19, 2005 at 2:46 am
Aah - the smoke still hasn't cleared from the 10 (or so) triggers that I just created and fired...I'm crushed by the fact that I'm resorting to this because of an "improperly designed application" -
The only thing I have against triggers is the fact that if you have too many of them it's easy to let it all get "out of control" resulting in much bloodshed & mayhem...so I usually give them a wide berth unless they are "the last resort"..
**ASCII stupid question, get a stupid ANSI !!!**
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply