greetings!! the below trigger works fine in SQL 2000 and doesn't take
up much resources, it's a very simple solution to trim text fields at
input in SQL. I know a lot of folks will say to create input masks at
the UI level and that SQL is a restricted back-end DB, but to be quite
honest I don't trust those UI guys and as a DBA I will have to clean
the mess when they forget to validate. Hope it can be usefull to any
of you too. ;)
----------------------------------------------------------------------
CREATE TRIGGER [TRIMMER_TGR] ON [dbo].[MyTable]
AFTER INSERT, UPDATE
AS
IF UPDATE (MyStringField)
DECLARE @TRIMMEDFIELD NVARCHAR(50)
DECLARE @MYID INT
SELECT @TRIMMEDFIELD = MyStringField from Inserted
SELECT @MYID = ID from Inserted
BEGIN
UPDATE tblDocket SET MyStringField = RTRIM(LTRIM(@TRIMMEDFIELD))
WHERE ID = @MYID
END