Member_2_6478753
asked on
trigger on insert to update column if contain top 2012 and replace by top 2013
i have the following table
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP 1000 [ActionId]
,[Text]
,[UserId]
,[type]
,[ActionTypeId]
FROM [HITV_Filtration].[TvUser] .[Sendsms]
where Text like '%top5 2012%'
order by actionid desc
i want to replace each new record inserted in [HITV_Filtration].[TvUser] .[Sendsms]
contain '%top5 2012%' and replace only the top5 2012 by top5 2013
the Text is like : vote to 23232 for top5 2012 XXXX
it should be replacd by vote to 23232 for top5 2012 XXX
??? i should care on update the primarykey is actionid
please can anyone help me on write this function
/****** Script for SelectTopNRows command from SSMS ******/
SELECT TOP 1000 [ActionId]
,[Text]
,[UserId]
,[type]
,[ActionTypeId]
FROM [HITV_Filtration].[TvUser]
where Text like '%top5 2012%'
order by actionid desc
i want to replace each new record inserted in [HITV_Filtration].[TvUser]
contain '%top5 2012%' and replace only the top5 2012 by top5 2013
the Text is like : vote to 23232 for top5 2012 XXXX
it should be replacd by vote to 23232 for top5 2012 XXX
??? i should care on update the primarykey is actionid
please can anyone help me on write this function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
[ActionId] [bigint] NOT NULL,
[Text] [varchar](4000) NULL,
[UserId] [int] NULL,
[type] [tinyint] NULL,
[ActionTypeId] AS (CONVERT([tinyint],(7),(0)
CONSTRAINT [PK_Message] PRIMARY KEY CLUSTERED
(
[ActionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE TRIGGER dbo.tri_Test_Insert_Trigge
ON [TvUser].[Sendsms] FOR INSERT
AS
BEGIN
UPDATE T
SET Text = // replace function ??
FROM
INSERTED I
INNER JOIN dbo.[TvUser].[Sendsms] T ON
T.ActionId = I.ActionId
WHERE .. TEXT LIKE ;%TOP5 2012%'
END
GO
please help :S