AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / dba / 问题 / 285456
Accepted
boog
boog
Asked: 2021-02-16 12:49:52 +0800 CST2021-02-16 12:49:52 +0800 CST 2021-02-16 12:49:52 +0800 CST

为 Sybase SQLAnywhere 16 创建触发器

  • 772

按照这些文档,我一直在尝试为 Sybase SAP SQLAnywhere 16 数据库创建触发器。

目前它在第 15/16 行(更新语句)上出现 -131 语法错误,但我没有在语法中看到任何错误。我在这里做错了什么?

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;
    set @parentRef = (select top 1 "parent_ref" from "inserted");
    if (@parentRef <> '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;
            declare @tabid integer;
            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
                declare @recProvider varchar(255),@recsRequested varchar(255),@dateFrom "datetime",@dateTo "datetime"
                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;
trigger sybase-sql-anywhere
  • 1 1 个回答
  • 92 Views

1 个回答

  • Voted
  1. Best Answer
    Justin W
    2021-02-17T10:08:35+08:002021-02-17T10:08:35+08:00

    我认为您遇到的问题是由 T-SQL (ASE) 语法和 SQLA (Watcom) 语法的混合引起的。您可以在 SQLA 中使用 T-SQL 触发器 - 但有很多限制。如果可以,最好重新编写。

    这符合,是否有效,我不知道!(更改都在 DECLARE 语句中。每个变量一个,从时间戳数据类型中删除双引号(根据 markp-fuso 的注释)。如果您确实需要在代码的后面进一步使用局部变量,则必须在开头声明它们一个新的 BEGIN / END 块)

    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 <> '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;
    
    • 0

相关问题

  • 明智地使用触发器来更新另一个表?

  • 将结果集存储在触发器中的临时表、变量或单独变量中

  • 触发器:将删除的行移动到存档表

  • 从 SQL Server 2000 到 SQL Server 2008 的死锁错误

  • 在触发器中,我能否确定列是否明确设置为值或未在更新语句中提及?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目

    • 12 个回答
  • Marko Smith

    如何让sqlplus的输出出现在一行中?

    • 3 个回答
  • Marko Smith

    选择具有最大日期或最晚日期的日期

    • 3 个回答
  • Marko Smith

    如何列出 PostgreSQL 中的所有模式?

    • 4 个回答
  • Marko Smith

    列出指定表的所有列

    • 5 个回答
  • Marko Smith

    如何在不修改我自己的 tnsnames.ora 的情况下使用 sqlplus 连接到位于另一台主机上的 Oracle 数据库

    • 4 个回答
  • Marko Smith

    你如何mysqldump特定的表?

    • 4 个回答
  • Marko Smith

    使用 psql 列出数据库权限

    • 10 个回答
  • Marko Smith

    如何从 PostgreSQL 中的选择查询中将值插入表中?

    • 4 个回答
  • Marko Smith

    如何使用 psql 列出所有数据库和表?

    • 7 个回答
  • Martin Hope
    Jin 连接到 PostgreSQL 服务器:致命:主机没有 pg_hba.conf 条目 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane 如何列出 PostgreSQL 中的所有模式? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh 为什么事务日志不断增长或空间不足? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland 列出指定表的所有列 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney MySQL 能否合理地对数十亿行执行查询? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx 如何监控大型 .sql 文件的导入进度? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison 你如何mysqldump特定的表? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 对 SQL 查询进行计时? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas 如何从 PostgreSQL 中的选择查询中将值插入表中? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas 如何使用 psql 列出所有数据库和表? 2011-02-18 00:45:49 +0800 CST

热门标签

sql-server mysql postgresql sql-server-2014 sql-server-2016 oracle sql-server-2008 database-design query-performance sql-server-2017

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve