Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

trigger on insert to update column if contain top 2012 and replace by top 2013

Posted on 2013-01-05
2
Medium Priority
?
315 Views
Last Modified: 2013-01-05
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
0
Comment
Question by:afifosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Author Comment

by:afifosh
ID: 38747509
CREATE TABLE [TvUser].[Sendsms](
      [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_Trigger
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
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 38747690
the Text is like : vote to 23232 for top5 2012  XXXX
it should be replacd by vote to 23232 for top5 2012 XXX
I suspect you meant:
the Text is like : vote to 23232 for top5 2012  XXXX
it should be replacd by vote to 23232 for top5 2013 XXX

If that is the case then try it like this:
UPDATE  T
    SET     [Text] = REPLACE([Text], 'TOP5 2012', 'TOP5 2013')
    FROM    INSERTED I
            INNER JOIN dbo.[TvUser].[Sendsms] T ON T.ActionId = I.ActionId
    WHERE   [Text] LIKE '%TOP5 2012%'

Open in new window

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question