AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / dba / Perguntas / 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

Criação de gatilho para Sybase SQLAnywhere 16

  • 772

Eu tenho tido dificuldade em tentar criar um gatilho para um banco de dados Sybase SAP SQLAnywhere 16 seguindo estes documentos.

Atualmente está com erro de sintaxe -131 na linha 15/16 (a instrução de atualização), mas não vejo nenhum erro na sintaxe. O que eu estou fazendo errado aqui?

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 respostas
  • 92 Views

1 respostas

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

    Acho que o problema que você está enfrentando é causado por obter uma mistura de sintaxe T-SQL (ASE) e sintaxe SQLA (Watcom). Você pode usar gatilhos T-SQL no SQLA - mas com muitas limitações. É melhor fazer uma reescrita se você puder.

    Isso está em conformidade, se funciona, não tenho ideia! (As mudanças estão todas nas instruções DECLARE. Uma por variável, aspas duplas removidas do tipo de dados timestamp (conforme comentário do markp-fuso). Se você realmente precisa de variáveis ​​locais mais abaixo no código, você deve declará-las no início do um novo bloco 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

relate perguntas

  • É sábio usar o gatilho para atualizar outra tabela?

  • armazenar conjunto de resultados em tabela temporária, variável ou variáveis ​​separadas dentro de um gatilho

  • Gatilho: mova as linhas excluídas para a tabela de arquivo

  • Erro de impasse do SQL Server 2000 para o SQL Server 2008

  • Em um gatilho, posso determinar se uma coluna foi explicitamente definida como um valor ou não foi mencionada na instrução de atualização?

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    conectar ao servidor PostgreSQL: FATAL: nenhuma entrada pg_hba.conf para o host

    • 12 respostas
  • Marko Smith

    Como fazer a saída do sqlplus aparecer em uma linha?

    • 3 respostas
  • Marko Smith

    Selecione qual tem data máxima ou data mais recente

    • 3 respostas
  • Marko Smith

    Como faço para listar todos os esquemas no PostgreSQL?

    • 4 respostas
  • Marko Smith

    Listar todas as colunas de uma tabela especificada

    • 5 respostas
  • Marko Smith

    Como usar o sqlplus para se conectar a um banco de dados Oracle localizado em outro host sem modificar meu próprio tnsnames.ora

    • 4 respostas
  • Marko Smith

    Como você mysqldump tabela (s) específica (s)?

    • 4 respostas
  • Marko Smith

    Listar os privilégios do banco de dados usando o psql

    • 10 respostas
  • Marko Smith

    Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL?

    • 4 respostas
  • Marko Smith

    Como faço para listar todos os bancos de dados e tabelas usando o psql?

    • 7 respostas
  • Martin Hope
    Jin conectar ao servidor PostgreSQL: FATAL: nenhuma entrada pg_hba.conf para o host 2014-12-02 02:54:58 +0800 CST
  • Martin Hope
    Stéphane Como faço para listar todos os esquemas no PostgreSQL? 2013-04-16 11:19:16 +0800 CST
  • Martin Hope
    Mike Walsh Por que o log de transações continua crescendo ou fica sem espaço? 2012-12-05 18:11:22 +0800 CST
  • Martin Hope
    Stephane Rolland Listar todas as colunas de uma tabela especificada 2012-08-14 04:44:44 +0800 CST
  • Martin Hope
    haxney O MySQL pode realizar consultas razoavelmente em bilhões de linhas? 2012-07-03 11:36:13 +0800 CST
  • Martin Hope
    qazwsx Como posso monitorar o andamento de uma importação de um arquivo .sql grande? 2012-05-03 08:54:41 +0800 CST
  • Martin Hope
    markdorison Como você mysqldump tabela (s) específica (s)? 2011-12-17 12:39:37 +0800 CST
  • Martin Hope
    Jonas Como posso cronometrar consultas SQL usando psql? 2011-06-04 02:22:54 +0800 CST
  • Martin Hope
    Jonas Como inserir valores em uma tabela de uma consulta de seleção no PostgreSQL? 2011-05-28 00:33:05 +0800 CST
  • Martin Hope
    Jonas Como faço para listar todos os bancos de dados e tabelas usando o psql? 2011-02-18 00:45:49 +0800 CST

Hot tag

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

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve