trim prefix

I need to change the following trigger so that it removes any prefix not just "CIS-".  So everything left of the first dash including the dash needs to be removed.  We want to keep the trimming of the trailing = sign as well.  Can someone assist me in how to modify this trigger to do this?  Thanks.

ALTER TRIGGER [dbo].[Dvx_TrimCIS-VNDITNUM]
ON [dbo].[IV00103]
AFTER INSERT, UPDATE
AS
SET NOCOUNT ON

UPDATE IV00103
SET
    VNDITNUM = REPLACE(SUBSTRING(IV00103.VNDITNUM,
        CASE WHEN IV00103.VNDITNUM LIKE 'CIS-%' THEN 5 ELSE 1 END,
        LEN(IV00103.VNDITNUM) -
        CASE WHEN IV00103.VNDITNUM LIKE 'CIS-%' THEN 4 ELSE 0 END),
        '=', '')
FROM IV00103
INNER JOIN Inserted I ON
      IV00103.ITEMNMBR = I.ITEMNMBR and
      IV00103.VENDORID = I.VENDORID and
      IV00103.ITMVNDTY = I.ITMVNDTY
WHERE
      IV00103.VNDITNUM LIKE 'CIS-%' OR
      RIGHT(IV00103.VNDITNUM, 1) = '='


GO
LVL 2
mike247Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark WillsTopic AdvisorCommented:
Not exactly sure what you want to do, but you can do
ALTER TRIGGER Dvx_TrimCIS-VNDITNUM on YourTableName
AFTER INSERT,UPDATE   
AS   
-- etc

Open in new window

But if it is in the name of the trigger, then drop the trigger first and redefine it.

Have a read of : https://docs.microsoft.com/en-us/sql/t-sql/statements/drop-trigger-transact-sql
0
Scott PletcherSenior DBACommented:
UPDATE IV00103
SET
    VNDITNUM = REPLACE(SUBSTRING(IV00103.VNDITNUM, CHARINDEX('-', IV00103.VNDITNUM) + 1, 8000), '=', '')
FROM IV00103
INNER JOIN Inserted I ON
      IV00103.ITEMNMBR = I.ITEMNMBR and
      IV00103.VENDORID = I.VENDORID and
      IV00103.ITMVNDTY = I.ITMVNDTY
WHERE
      IV00103.VNDITNUM LIKE '%-%' OR
      IV00103.VNDITNUM LIKE '%='
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
Something like:
UPDATE IV00103 
SET VNDITNUM = REPLACE(SUBSTRING(IV00103.VNDITNUM, CHARINDEX('-', IV00103.VNDITNUM)+1, LEN(IV00103.VNDITNUM) - CHARINDEX('-', IV00103.VNDITNUM)),'=', '')
FROM IV00103
INNER JOIN Inserted I ON
      IV00103.ITEMNMBR = I.ITEMNMBR and 
      IV00103.VENDORID = I.VENDORID and 
      IV00103.ITMVNDTY = I.ITMVNDTY
WHERE
      IV00103.VNDITNUM LIKE 'CIS-%' OR
      RIGHT(IV00103.VNDITNUM, 1) = '='

Open in new window

0
mike247Author Commented:
This works.  I just needed to make it so that it only fires only upon insert and not upon update.  Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.