Kiwiman
Registered User
- Local time
- Today, 10:11
- Joined
- Apr 27, 2008
- Messages
- 799
Hi All
This is my first real attempt at a trigger. What I am attempting to do is remove a carriage return that is included in one of the fields that is uploaded into SQL Server 2005. This syntax plays havoc with a process later on in the process - so I want to remove this immediately. We are trying to get this removed at source, but in the interim...
This appears to work, as when I run a select query on the table, I can not find any records with a carriage return - prior to this trigger being implemented there would have been, after a particular file was uploaded.
I am however unsure if this can be improved upon. Any comments on the syntax and improvements \ deficiencies would be welcome.
As always thanks for your help.
This is my first real attempt at a trigger. What I am attempting to do is remove a carriage return that is included in one of the fields that is uploaded into SQL Server 2005. This syntax plays havoc with a process later on in the process - so I want to remove this immediately. We are trying to get this removed at source, but in the interim...
This appears to work, as when I run a select query on the table, I can not find any records with a carriage return - prior to this trigger being implemented there would have been, after a particular file was uploaded.
I am however unsure if this can be improved upon. Any comments on the syntax and improvements \ deficiencies would be welcome.
As always thanks for your help.
Code:
-- ================================================
-- Template generated from Template Explorer using:
-- Create Trigger (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- See additional Create Trigger templates for more
-- examples of different Trigger statements.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE TRIGGER [dbo].[tr_Fastpay_Feed]
ON PROD_VAR_FEED
AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- replace any carriage returns with an empty string
update
t1
set
t1.taxperiod = replace(cast(t1.taxperiod AS varchar(8000)), char(13), '')
from
prod_var_feed t1
inner join
inserted t2 on
t1.id = t2.id
and t1.interid = t2.interid
and t1.contract = t2.contract
and t1.payrollid = t2.payrollid
and t1.taxperiod = t2.taxperiod
and t1.runid = t2.runid
and t1.source = t2.source
and t1.feeddate = t2.feeddate
where
t1.source = 'FastPay'
and (t1.taxperiod LIKE '%'+char(13)+'%')
END
GO