Update Trigger Assistance - Update Same Row More than Once?

Good morning,
I'm new to Triggers and am not understanding why this is not working.  I've tried the web and none of the articles seem to answer my question.  What I'm trying to do is clean a string and standardize some data the users input into a 1000 character
varchar field.  I have a source table which has a trigger on it that inserts a limited number of columns that we'll use for reporting purposes.  After the row has been inserted into the table (referred to as "destination" in the code block),
I'm looking to update the comments string, capitalizing the first character of the string, standardizing spacing after a colon, removing hyphens at the beginning of the string.  The source and destination tables both have the comments field as a varchar
1000, not null data type with a key id between the source and destination tables.  At another segment of our system, there were errors reporting nulls and when this was removed, everything cleared up.  I can do a series of replace statements when
the data is required in reports but would rather have it clean in the destination table.  The code is below:
CREATE TRIGGER [dbo].[destination_Update_trg]
ON [dbo].[destination]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF EXISTS (SELECT *
FROM destination C
JOIN INSERTED I
ON I.PrimaryKeyID = C.PrimaryKey
WHERE I.Comments IS NOT NULL AND I.Comments <> '')
BEGIN
UPDATE T
SET T.Comments =
CASE
WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %'
THEN SUBSTRING(T.Comments, 3, 1000)
END
FROM destination T
JOIN INSERTED I
ON T.primarykey = I.primarykey
WHERE T.primarykey = I.primarykey
UPDATE T
SET T.Comments = UPPER(LEFT(CAST(T.Comments AS VARCHAR (1000)), 1)) + SUBSTRING(CAST(T.Comments AS VARCHAR (1000)), 2, 1000)
FROM destination T
JOIN INSERTED I
ON T.primarykey = I.primarykey
WHERE T.primarykey = I.primarykey
UPDATE T
SET T.Comments = REPLACE(SUBSTRING(T.Comments, 1, 1000), ': ', ': ')-- '[A-9]: [A-9]'
FROM destination T
JOIN INSERTED I
ON T.primarykey = I.primarykey
WHERE T.primarykey = I.primarykey
AND SUBSTRING(T.Comments, 1, 1000) LIKE '%[A-Z]%: [A-Z]%'
END
RETURN
END;
GO
Perhaps there's a better way to accomplish the task. I appreciate your review and assistance. Thank you.

First, the trigger only fires when you do an UPDATE.  I'm not sure from your description whether or not you are expecting this trigger to fire when you do an insert on dbo.destination.  If you want it to fire on INSERTs, then you need to specify
FOR INSERT (or FOR INSERT, UPDATE if you want it to fire on both inserts and updates).
More importantly, the first update in your trigger does
SET T.Comments =
CASE
WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
END
When you do a CASE and you don't have an ELSE clause, there is an implicit ELSE NULL clause added.  So your update is equivalent to
SET T.Comments =
CASE
WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
ELSE NULL
END
So your very first update sets the Comments column to NULL in every row that was updated where the Comments column is not like '- %'.  You want to change the case statement to be
SET T.Comments =
CASE
WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
ELSE T.Comments
END
(Or you can put the test in the where clause so that you only update those rows where the Comments column is like '- %'.  That would look like
UPDATE T
SET T.Comments = SUBSTRING(T.Comments, 3, 1000)
END
FROM destination T
JOIN INSERTED I
ON T.primarykey = I.primarykey
WHERE LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %'
(Note that you do not need to include the T.Comments <> '' because if T.Comments is Like '- %', then it cannot be the empty string and you do not need to include WHERE T.primarykey = I.primarykey because you know that is true since you did an inner
join on T.primarykey = I.primarykey.
Tom

Similar Messages

  • How do I repeat the same row more than once in report 10g

    How do I repeat the same row more than once in report 10g
    So I can print the bar code more than once
    in report;
    Edited by: user11106555 on May 9, 2009 5:50 AM

    GREAT THAN X MAN
    It is already working, but with the first ROW
    select ename from emp
    CONNECT BY ROWNUM<=5
    ENAME
    SMITH
    SMITH
    SMITH
    SMITH
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    BUT I want this result
    Item1
    Item2
    Item3
    to
    Item1
    Item1
    Item1
    Item2
    Item2
    Item2
    Item3
    Item3
    Item3

  • Backups to same DVD more than once

    I have just started to use PSE 7 and have moved all my photos into it.  I did the initial backup to a DVD but now that I want to backup my new pictures, it seems to want a new DVD.  I don't take all that many pictures so it would take me some months fill up a DVD.  It doesn't seem to like DVD-R and with DVD-RW, it tells me there is something on the DVD and do I want to erase it.  How do I use PSE7 to backup or copy pictures to the same DVD more than once?  Thanks.

    As far as I know, one can burn contents to a DVD only once...
    If you’re using a DVD-RW you have to erase the old contents first...
    On can burn a CD several times until filled up though...
    You might consider using an external Firewire Hard-drive for your backup...?
    Regards
    Nolan
    PS:
    Please check this one out...
    http://freeridecoding.com/burnagainfs/
    (guess, "Windows" offers something similar...)

  • Use of same filed more than once in module pool program.

    hi Good day,
    i want to use a filed on the screen more than once.
    ex : T7EHS00_EXA_PHY-UNIT
    the reason why i want to use this field more than once is b'coz it has SEARCH HELP.
    If i use this filed search help is created internally.
    to be more specific :
    i have
    screen field    screen field
    xys                unit of meas.
    abc                unit of meas.
    def                 unit of meas
    ghi                 unit of meas.
    jkl                  unit of meas.
    but SAP Does not accept the same field more than once.
    in this case what can i do?
    thank you,
    J.

    Hi Jacob,
    use like this....
    data : i1 type T7EHS00_EXA_PHY-UNIT ,
            i2 type T7EHS00_EXA_PHY-UNIT,
            i3 type T7EHS00_EXA_PHY-UNIT,
            i4 type T7EHS00_EXA_PHY-UNIT.
    In the screen properties,
    Give search Help-----> H_T006
    Declare the name in program as given to IO filed name...
    Hope you Understood...
    Regards,
    Vijay SR

  • How do I get itunes to not list the same artist more than once?

    How do I get ituens to not list the same artist more than once?  I have tried editing the info, sorting different ways and sometimes it works and sometimes not...it's very frustrating to me to have the same artist listed multiple times...

    Setting a common Album Artist for each Album does most of the work. For deeper problems see Grouping tracks into albums.
    In general you need to make sure that all the values in the tags are used consistently. Same spelling, same capitalization, same accents, no leading, trailing, or multiple spaces, and each value of Artist, Album Artist or Album should only be associated with one value of Sort Artist, Sort Album Artist or Sort Album respectively.
    tt2

  • HT1933 what if I bought the same game more than once from i tunes by mistake how can i claim a refund?

    what if I bought the same game more than once, How can I claim a refund from I tunes store?

    You can try contacting iTunes Support and see if they will refund or credit you : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • How to retrict user cannot open the same form more than once (Forms 6i)

    Our users always open the same forms more than once. For example the customer form, the user may access a customer record in the first form, however, he will open a new customer form to edit the same record, the result is he cannot save the record because the record is locked in the first customer form.
    How can I control the user cannot open the same form more than 1 time.
    Best Regards,
    Kane

    The customer form is only an example, I found there will cause a lot of problems is I cannot control the user from calling 1 program more than 1 than within application. Sometimes a user (not good in using computer) will overlap the form for many times.....
    Is there any simple way to do that?...can I have some PL/SQL statement or build-in functions that let me easily found our what forms the user has already opened, then I can control whether I let him open this form or not.
    Urgent...please
    Thanks

  • HT204370 Can I rent the same movie more than once?

    Can I rent the same movie more than once?

    Yes, as long as you do so within the 24/48 hour period.
    (73178)

  • Archiving same data more than once due to overlapping variant values

    Hi all,
    i had accidently run 2 archiving jobs on the same data. For instance, job 1 was archiving for company code IN ( where the company code was from IN00 till ZZ00), which was the unwanted job. The second archive job archived data from IN99 till INZZ ( not the whole IN company code ).
    These 2 jobs failed due to log fulll ( the data was too huge to be archived), however when i expand the jobs in the failed SARA session, the archive files has up to 100 MB size.
    Below are some of the problems which will incur if we archive the same data more than once ( which i found from  my online search )
    - some archiving objects require that data only exists once in the archive therefore duplicate data can lead to erroneous results in the totals of archived data
    - Archiving the data again will affect checksum. Checksum normally conducted before and after archiving process and its purpose is to validate whether the same file contents exist in the newly created archive files as compare the original data.
    Could anyone advice me on how to overcome this multiple archiving on the same data issue. Apart from above stated impact, what are the other problems of multiple archiving on same data?
    The failed archived sessions are currently in "Incomplete Archiving Session" and in 1 week time they will be deleted by archive delete jobs and will be moved to "Completed Archive Session". I highly appreciate if anyone could help
    Source of finding:
    http://help.sap.com/saphelp_nw73/helpdata/en/4d/8c7890910b154ee10000000a42189e/content.htm
    http://help.sap.com/saphelp_nwpi71/helpdata/en/8d/3e4fc6462a11d189000000e8323d3a/frameset.htm
    http://help.sap.com/saphelp_nw70/helpdata/en/8d/3e4fc6462a11d189000000e8323d3a/content.htm

    Hello,
    There are several issues here.  In this case it seems pretty clear cut that you did not want the first variant to be executed.  Hopefully none of the deletions have taken place for this archive run.
    In cases where you have overlapping selection criteria and some of the deletions have been processed you can be in a very difficult situation.  The best advise that I have would be to check your archive info structure CATALOG definition and make sure that both the archive file and the offset fields are set to DISPLAY fields and not KEY fields.
    If your file and offset are key fields then when you use the archive info structure you would pull up more than one copy of the archived document.
    Example:  FI document 12345 was archived and deleted in archive run 1 and archive run 2.
    The search for the archive info structure when the file and offset are keys fields would return two results.
    12345 from run 1
    12345 from run 2
    If the CATALOG has the file and offset as display only fields you would only return one result
    12345 from (whichever deletion file was processed first)
    The second deletion process would have a warning message in the job log that not all records were inserted.
    Please note that any direct access of the data archive file that bypasses the archive info structure and goes directly to the data archiving files would still show two documents and not a single document.
    Regards,
    Kirby Arnold

  • Load rule to update alternate hierarchy with shared members more than once

    I have a aso cube with an alternate hierarchy that is not stored because the shared members appear more than once. Below is how my alternate hierarchy looks.
    Dept
    Class
    VolumeLevel
    StoreNum
    where StoreNum is the shared member.
    I build the cube using eis every weekend. The VolumeGroup changes everyday, so I was thinking of using a sql load rule to update the outline everyday. Assuming that the data and the aggregation does not get cleared. Is it possible to do it using sql load rule?
    Thanks,

    You can check here if you are satisfying the conditions for creating shared members under the Hierarchy (refer to Alternate Hierarchies). Plz note that rules for shared members are different in ASO world.
    http://docs.oracle.com/cd/E17236_01/epm.1112/esb_dbag/frameset.htm?acrtapdb.html
    Otherwise there is no reason why you should not be able to create a shared member.
    I am able to create a hierarchy using a sample file like this ->
    EN_MAIN, EN_500000
    EN_500000, EN_49999
    EN_ALT, C_500000
    C_500000, EN_49999
    ENTITY (Multiple Hierarchies Enabled)
    |-EN_MAIN (Stored)
    |--EN_500000
    |---EN_49999
    |-EN_ALT (Stored)
    |--C_500000
    |---EN_49999 (Shared)
    The rule file has only "Allow Property Changes" on.
    Thanks,
    Sunil

  • Using firefox 5 - when ever I try to use the same key more than once in a row, it does not work. Hitting the multiple times does nothing at all. How can this be corrected. HELP!!!

    everything that needs to be done on the keyboard is effected - letters, numbers, backspace, directionals, delete, home, end, page up, page down, '''all keys that are pressed more than once''' It does not matter what webpage I am on.
    PLEASE HELP
    this is very frustrating

    You may have switched on an accessibility feature called FilterKeys by keeping the Shift key pressed for too long.
    * http://www.microsoft.com/enable/products/windowsxp/default.aspx
    *http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/access_filterkeys_turnon.mspx?mfr=true

  • Getting the same text more than once

    I keep getting the same numerous texts more than once from my friends and one of my friends even said that they were getting my texts out of order. Is it my phone or the network?

    It's easy to burn another copy of a DVD if you have already burnt a copy of it before. Just click the "Format" icon in the toolbar. It will pop up with a window with some options. You shouldn't have to change any of these options, just make sure that the Output Device is set to your DVD drive, which it should be set to by default. Just click the "Burn" button, pop in a DVD, and you're good to go.
    If you've made a few changes to the DVD, you can use the "Build/Format" button in the toolbar. It will pop up with a window similar to that of the Format window. Click "Build & Burn." It will tell you that a VIDEO_TS directory already exists, and it can reuse as much of it as possible. You can then click "Reuse" to build the new portions of the DVD, and then it will burn it on a DVD.
    Hope this helps.

  • How to call the same query more than once with different selection criteria

    Hi,
    Please do anybody know how to solve this issue? I need to call one query with the fixed structure more than once with different selection criteria. For example. I have following data
    Sales organization XX
                         Income 2008  Income 2009
    Customer A       10                 20
    Customer B        30                  0
    Sales organization YY
                         Income 2008  Income 2009
    Customer A        20                5
    Customer B        50                10
    Now, I need this. At the selection screen of query, user fill variable  charakteristic "Sales organization" with interval  XX - YY, than I need to generate two separate results per sales organization, one for Sales Organization XX and the second for SO YYwhich will be displayed each on separate page, where result for SO YY will be dispayed under result for SO YY. Are there some options how to do it for example in Report Designer or WAD or with programming? In Report Designer is possible to use one query more than once, but I dont know how to force each query in RD to display result only for one Sales Organization, which will be defined in selection screen.
    Thank you very much
    J.

    Hello,
    thanks to all for cooperation. Finally we solved this issue with the following way..
    User fill appropriate SO on the selection screen, which is defined as range. This will resulte, that selected SO are listed in report below each othe (standard behavior). Required solution we achieved with the Report Designer, we set page break under each Result row of RD. This caused, that report is divided into required part per SO, which are stated each on separate page.
    J.

  • How can I add the same song more than once?

    how can I add the same song to my ipod shuffle more than once?

    Thanks. I tested it, and found that I can create a bookmark in FolderA, and them manually copy it to FolderB, FolderC, and FolderD.
    Once that is done, I tried the old method of "Bookmarks" --> "Bookmark This Page" and added it to FolderE. When I did that, it deleted the copy in FolderD but left the other three alone!
    This is fine with me. I personally think this is a bug, because I don't think that Firefox should ever delete a bookmark without asking me (or at least, informing me). But now that I understand the algorithm, I can work around it. Thanks!

  • Count certain rows more than once

    I have the sql below:
    select count(*), ind_encounter
    from (
    select x.sak_recip, x.dte_first_svc, x.ind_encounter
    from t_tmp x
    group by x.sak_recip, x.dte_first_svc, x.ind_encounter
    union all
    select x.sak_recip, x.dte_first_svc, x.ind_encounter
    from t_tmp x
    where x.sak_procedure in (1, 2, 3, 4) )
    group by ind_encounter
    What I need to do is count the sql in bold more than once. If one row in the table has sak_procedure = 1, I want to count that row 13 times. I know that if union 11 more sqls, I will count those 13 times.
    I would like to know if someone knows an easer way.
    thanks for your help

    try
    select count(*), ind_encounter,
             sum(cnt1) -- your counter
      from (select x.sak_recip, x.dte_first_svc, x.ind_encounter, count(*) * N cnt1
              from t_tmp x
             group by x.sak_recip, x.dte_first_svc, x.ind_encounter
            union all
            select x.sak_recip, x.dte_first_svc, x.ind_encounter, count(*) * M cnt1
              from t_tmp x
             where x.sak_procedure in (1, 2, 3, 4)
            group by x.sak_recip, x.dte_first_svc, x.ind_encounter
             group by ind_encounterEdited by: AlexAnd on Dec 4, 2011 11:21 PM

Maybe you are looking for

  • WebDynpro with embedded SAP GUI for HTML transaction

    Hello, I have been given a requirement for a WebDynpro application that will have some links and figures at the top and underneath that there will be a SAP GUI for HTML transaction visible. What is the best method for handling this type of scenario?

  • Report integration to forms in 10g IDS

    Hi My package was created using D2K 6.0 version. I donot have access to 6i. Converted the same in 9i first. The proceeded to 10g. While converting forms there were no problems. But reports is a different story. If i compile and run the rdf file in re

  • Extra blank space problem in af:selectOneChoice

    Hi All, I m using <af:selectOneChoice> to display few items in combo box. Now the problem is when the page gets load 1st time, its show an extra blank space in item list, but after selecting any item from the list page gets refreshed and reload again

  • No Exporting System for system ECP-100 in project ZECC_QGM

    Hi   we are using QGM Functionality in Solution Manager7.1 with SP08  for ECC Implementation project. last week we migrated your Solution manager system to a different Hardware, where there is a change in IP address, Host name and SID was changed. an

  • How to Invoke two java methods parallaly

    Hi, I need to invoke two Java methods parallaly ,for example if i am having two methods in a class public class Test {     public Test() {     public static void main(String[] args)     Test test = new Test();     String returnString1 = test.test1();