简体   繁体   English

使用触发器更新SQL中的记录时,在FileMaker中添加记录时,不能将OUTPUT子句与INTO子句一起使用

[英]Cannot use OUTPUT clause with INTO clause when using Triggers to update records in SQL, when adding a record in FileMaker

I know a similar question to this has been asked a fair few times on here, but none seem to give me the answer I need - specifically because I am talking about the relationship between SQL and FileMaker. 我知道类似的问题在这里已经被问过好几次了,但是似乎没有一个问题能给我我所需的答案-特别是因为我在谈论SQL与FileMaker之间的关系。

See, I'm not actually using an OUTPUT clause at all in my Trigger! 瞧,我实际上没有在触发器中使用OUTPUT子句! But FileMaker seems to either think I am, or insert something itself as an OUTPUT clause that I can't see. 但是FileMaker似乎以为我是,或者将某些东西本身插入为我看不到的OUTPUT子句。

Here is an example trigger: 这是一个示例触发器:

CREATE TRIGGER [dbo].[TRG_person__name] 
   ON  [dbo].[person] 
   AFTER INSERT,UPDATE
AS 
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

IF  UPDATE ( person_name_first ) 
    BEGIN

        UPDATE person
        SET person_name_first = dbo.mslTitleCase ( i.person_name_first )
        FROM person AS x
        JOIN inserted AS i ON x._pk_person = i._pk_person
        WHERE x._pk_person = i._pk_person

    END
--END IF


END

The mslTitleCase function has been declared and works, if I was to create a record using a SQL Query. 如果我要使用SQL查询创建记录,则必须声明并运行mslTitleCase函数。 But I can an error when creating a new record in FileMaker. 但是在FileMaker中创建新记录时出现错误。

Does anyone have any tips to find a way to stop this error in FileMaker? 有没有人有任何技巧来找到在FileMaker中停止此错误的方法?

Any guidance greatly appreciated. 任何指导,不胜感激。

Thank you 谢谢

Lewis 刘易斯

You may have other problems, but the correct syntax for the update is: 您可能还有其他问题,但是update的正确语法是:

    UPDATE p
        SET person_name_first = dbo.mslTitleCase ( i.person_name_first )
    FROM person p JOIN
         inserted i
         ON p._pk_person = i._pk_person
    WHERE p._pk_person = i._pk_person;

The important change is that the update references the table alias not the table name . 重要的变化是update引用了表别名而不是表名 I think p is a much better alias than x for a table named person . 对于一个名为person的表,我认为px好得多。

It sounds like your application is using the OUTPUT clause to directly return the modified data. 听起来您的应用程序正在使用OUTPUT子句直接返回修改后的数据。 If the table has any trigger, this is not allowed. 如果表有任何触发器,则不允许这样做。 They would have to output the modified data into a table, and then select the data from the table. 他们必须将修改后的数据输出到表中,然后从表中选择数据。

The issue is covered in this article: https://blogs.msdn.microsoft.com/sqlprogrammability/2008/07/11/update-with-output-clause-triggers-and-sqlmoreresults/ 本文涵盖了该问题: https : //blogs.msdn.microsoft.com/sqlprogrammability/2008/07/11/update-with-output-clause-triggers-and-sqlmoreresults/

If this is the case, you will not be able to add a trigger to the table. 在这种情况下,您将无法向该表添加触发器。 The corrections to the data will need to happen from an external source. 数据校正将需要从外部来源进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM