<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Please help me check trigger  error in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/please-help-me-check-trigger-error/qaa-p/13836857#M4867700</link>
    <description>&lt;P&gt;can you post what is the expected output?&lt;/P&gt;
&lt;P&gt;When I execute your same code, I get different output as in your last block.&lt;/P&gt;
&lt;P&gt;My --run looks so:&lt;/P&gt;
&lt;PRE&gt;UUID    goods            price    OLD_uuid
1       'test'           20.000
2       'apple,test'     20.000   1
&lt;/PRE&gt;</description>
    <pubDate>Sun, 17 Dec 2023 04:36:12 GMT</pubDate>
    <dc:creator>Baron</dc:creator>
    <dc:date>2023-12-17T04:36:12Z</dc:date>
    <item>
      <title>Please help me check trigger  error</title>
      <link>https://community.sap.com/t5/technology-q-a/please-help-me-check-trigger-error/qaq-p/13836855</link>
      <description>&lt;P&gt;When the updated value contains a comma, the trigger inserts the original column value,&lt;/P&gt;
&lt;P&gt;**&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;CREATE TABLE "DBA"."test_split" (
    "UUID" INTEGER NOT NULL DEFAULT AUTOINCREMENT,
    "goods" VARCHAR(90) NULL,
    "price" DECIMAL(111,3) NULL,
    "OLD_uuid" INTEGER NULL,
    CONSTRAINT "ID" PRIMARY KEY ( "UUID" ASC )
) IN "system";
COMMENT ON TABLE "DBA"."test_split" IS '
';
--insert demo data
INSERT INTO "DBA"."test_split" ("UUID","goods","price","OLD_uuid") VALUES(1,'apple',10.000,NULL)；
--create trigger where update 
CREATE TRIGGER "update_trigger" AFTER UPDATE OF "goods"
ORDER 1 ON "DBA"."test_split"
  REFERENCING OLD AS old_test_split NEW AS new_test_split
FOR EACH ROW  WHEN(  CHARINDEX(',', new_test_split.goods)&amp;gt;0)   -- Including commas to trigger business execution
BEGIN
     declare @old_uuid INTEGER ;
     declare @old_goods varchar(100);
     declare @old_price  int;
     declare @instert_new_goods varchar(100);
     select  uuid,goods,price into @old_uuid,@old_goods,@old_price  from test_split where Old_test_split.uuid=test_split.uuid ;
  select right(goods,len(goods)-CHARINDEX(',',goods)) into @instert_new_goods from  test_split where new_test_split.uuid=test_split.uuid; 
  --Replace Update
update  test_split set goods=@instert_new_goods from  test_split where new_test_split.uuid=test_split.uuid; 
--Reinsert old data and record uuid
INSERT INTO "DBA"."test_split" ("goods","price","OLD_uuid") 
VALUES(@old_goods,@old_price,@old_uuid)
END;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;**&lt;/P&gt;
&lt;P&gt;--run:&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;update test_split set goods='apple,test',price=20 where uuid=1;

UUID   goods     price    old_uuid
1      test       20        
2     apple       10      1
&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 15 Dec 2023 11:47:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/please-help-me-check-trigger-error/qaq-p/13836855</guid>
      <dc:creator>ximen</dc:creator>
      <dc:date>2023-12-15T11:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me check trigger  error</title>
      <link>https://community.sap.com/t5/technology-q-a/please-help-me-check-trigger-error/qaa-p/13836856#M4867699</link>
      <description>&lt;P&gt;I would debug this with the Stored Procedure debugger in SQL Central. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Navigate to the trigger source in SQL Central&lt;/LI&gt;
&lt;LI&gt;Select Mode | Debug&lt;/LI&gt;
&lt;LI&gt;Set a breakpoint after the first select&lt;/LI&gt;
&lt;LI&gt;Execute the update&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Examine the value set for the "@old__goods_". It is the values currently in the table - the update has completed by the time this trigger is fired. You should access the old values using Old_test_split.  &lt;/P&gt;</description>
      <pubDate>Sat, 16 Dec 2023 12:16:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/please-help-me-check-trigger-error/qaa-p/13836856#M4867699</guid>
      <dc:creator>chris_keating</dc:creator>
      <dc:date>2023-12-16T12:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Please help me check trigger  error</title>
      <link>https://community.sap.com/t5/technology-q-a/please-help-me-check-trigger-error/qaa-p/13836857#M4867700</link>
      <description>&lt;P&gt;can you post what is the expected output?&lt;/P&gt;
&lt;P&gt;When I execute your same code, I get different output as in your last block.&lt;/P&gt;
&lt;P&gt;My --run looks so:&lt;/P&gt;
&lt;PRE&gt;UUID    goods            price    OLD_uuid
1       'test'           20.000
2       'apple,test'     20.000   1
&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Dec 2023 04:36:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/please-help-me-check-trigger-error/qaa-p/13836857#M4867700</guid>
      <dc:creator>Baron</dc:creator>
      <dc:date>2023-12-17T04:36:12Z</dc:date>
    </item>
  </channel>
</rss>

