Trigger creation for Sybase SQLAnywhere 16 I've been having the hardest time trying to create a trigger for a Sybase SAP SQLAnywhere 16 database following these docs.
Currently it's -131 syntax erroring on line 15/16 (the update statement), but I don't see any error in the syntax. What am I doing wrong here?
create trigger &quot;DBA&quot;.&quot;WKM_autoFillCL143&quot; after insert order 2 on &quot;DBA&quot;.&quot;case_checklist&quot;
when ((select top 1 &quot;inserted&quot;.&quot;code&quot; from &quot;inserted&quot;) in( '143' ) )
  begin
    declare @parentRef integer; 
    declare @desc varchar(255); 
    declare @desc1 varchar(255); 
    declare @checkID integer;
    set @parentRef = (select top 1 &quot;parent_ref&quot; from &quot;inserted&quot;);
    if (@parentRef &lt;&gt; '0')
      then
        set @desc = (select &quot;description&quot; from &quot;case_checklist&quot; where &quot;checklist_id&quot; = @parentRef);
        if (@desc is not null)
          then
            set @checkID = (select top 1 &quot;checklist_id&quot; from &quot;inserted&quot;);
            update &quot;WKM_RecordChecklistMapping&quot; set &quot;c143&quot; = @checkID where &quot;c142&quot; = @parentRef;
            declare @tabid integer;
            set @tabid = (select top 1 &quot;tab_id&quot; from &quot;WKM_recordChecklistMapping&quot; where &quot;c142&quot; = @parentRef);
            set @tabid = (select top 1 &quot;tab_id&quot; from &quot;user_tab2_data&quot; where &quot;tab_id&quot; = @tabid);
            if (@tabid is not null)
              then
                declare @recProvider varchar(255),@recsRequested varchar(255),@dateFrom &quot;datetime&quot;,@dateTo &quot;datetime&quot;
                set @recProvider = (select top 1 &quot;Provider_Name&quot; from &quot;user_tab2_data&quot; where &quot;tab_id&quot; = @tabid);
                set @recsRequested = (select top 1 &quot;Records_Requested&quot; from &quot;user_tab2_data&quot; where &quot;tab_id&quot; = @tabid);
                set @dateFrom = (select top 1 &quot;For_Dates_From&quot; from &quot;user_tab2_data&quot; where &quot;tab_id&quot; = @tabid);
                set @dateTo = (select top 1 &quot;Through&quot; from &quot;user_tab2_data&quot; where &quot;tab_id&quot; = @tabid);
                set @desc1 = 'Receipt '+@recProvider+' Records? '+@recsRequested+', dates '+&quot;coalesce&quot;(convert(varchar(255),@dateFrom,1),'00/00/00')+' to '+&quot;coalesce&quot;(convert(varchar(255),@dateTo,1),'00/00/00');
                set @checkID = (select top 1 &quot;checklist_id&quot; from &quot;inserted&quot;);
                update &quot;case_checklist&quot; set &quot;description&quot; = @desc1,&quot;staff_assigned&quot; = 'ZKS',&quot;due_date&quot; = (&quot;today&quot;()+7) where &quot;checklist_id&quot; = @checkID
              end if;
          end if;
      end if;
  end;
I think the problem you are running into is caused by getting a mixture of T-SQL (ASE) syntax and SQLA (Watcom) syntax. You can use T-SQL triggers in SQLA - but with quite a lot of limitations. It better to do a re-write if you can.
This complies, whether it works, I have no idea! (The changes are all in the DECLARE statements. One per variable, double quotes removed from the timestamp datatype (as per markp-fuso's comment). If you really need local variables further down the code, you have to declare them at the beginning of a new BEGIN / END block)
create trigger DBA.WKM_autoFillCL143 after insert order 2 on DBA.Case_Checklist
  when ((select top 1 inserted.code from inserted) in( '143' ) )
  begin
    declare @parentRef integer; 
    declare @desc varchar(255); 
    declare @desc1 varchar(255); 
    declare @checkID integer;
    declare @tabid integer;
    declare @recProvider varchar(255);
    declare @recsRequested varchar(255);
    declare @dateFrom datetime;
    declare @dateTo datetime;
    set @parentRef = (select top 1 parent_ref from inserted);
    if (@parentRef &lt;&gt; '0')
      then
        set @desc = (select description from case_checklist where checklist_id = @parentRef);
        if (@desc is not null)
          then
            set @checkID = (select top 1 checklist_id from inserted);
            update WKM_RecordChecklistMapping set c143 = @checkID where c142 = @parentRef;
            set @tabid = (select top 1 tab_id from WKM_recordChecklistMapping where c142 = @parentRef);
            set @tabid = (select top 1 tab_id from user_tab2_data where tab_id = @tabid);
            if (@tabid is not null)
              then
                set @recProvider = (select top 1 Provider_Name from user_tab2_data where tab_id = @tabid);
                set @recsRequested = (select top 1 Records_Requested from user_tab2_data where tab_id = @tabid);
                set @dateFrom = (select top 1 For_Dates_From from user_tab2_data where tab_id = @tabid);
                set @dateTo = (select top 1 Through from user_tab2_data where tab_id = @tabid);
                set @desc1 = 'Receipt '+@recProvider+' Records? '+@recsRequested+', dates '+coalesce(convert(varchar(255),@dateFrom,1),'00/00/00')+' to '+coalesce(convert(varchar(255),@dateTo,1),'00/00/00');
                set @checkID = (select top 1 checklist_id from inserted);
                update case_checklist set description = @desc1,staff_assigned = 'ZKS',due_date = (today()+7) where checklist_id = @checkID
              end if;
          end if;
      end if;
  end;