• domleg (4/9/2014)


    Figured it out, thanks for pointing me in the right direction, I just right clicked the triggers in the remlactation table and clicked on new trigger, followed the step by step and replace all with what I wanted.

    Final result was this... tested and working...

    USE [Lely]

    GO

    /****** Object: Trigger [dbo].[A2FixTeatCoordinates] Script Date: 04/09/2014

    11:27:58 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    -- =============================================

    -- Author:<Author,,Name>

    -- Create date: <Create Date,,>

    -- Description:<Description,,>

    -- =============================================

    CREATE TRIGGER [dbo].[A2FixTeatCoordinates]

    ON [dbo].[RemLactation]

    AFTER INSERT,DELETE,UPDATE

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    -- Insert statements for trigger here

    UPdate dbo.PrmMilkVisit

    Set MviLFXPosition = 60, MviLFYPosition = 660, MviLFZPosition = 510, MviLRXPosition =

    30, MviLRYPosition = 780,

    MviLRZPosition = 520, MviRFXPosition = -70, MviRFYPosition = 670, MviRFZPosition = 500,

    MviRRXPosition = -30,

    MviRRYPosition = 790, MviRRZPosition = 520

    Where MviLFXPosition = 0 AND MviLFYPosition = 0 and MviLFZPosition = 0 and

    MviLRXPosition = 0 and MviLRYPosition = 0

    and MviLRZPosition = 0 and MviRFXPosition = 0 and MviRFYPosition = 0 and MviRFZPosition

    = 0 and MviRRXPosition = 0

    and MviRRYPosition = 0 and MviRRZPosition = 0

    END

    GO

    This doesn't look right to me. You are not referencing inserted or deleted. That means this will run execute this code and update any values that meet your condition in the entire table, not just any rows inserted or updated. Why in the world do you have this running for a delete???

    Also, do you realize that this will only modify data when every single condition is true? If ANY column in your where is something other than 0 this will not do anything. It will not do anything if ANY of these are NULL.

    Where MviLFXPosition = 0 AND MviLFYPosition = 0 and MviLFZPosition = 0 and

    MviLRXPosition = 0 and MviLRYPosition = 0

    and MviLRZPosition = 0 and MviRFXPosition = 0 and MviRFYPosition = 0 and MviRFZPosition

    = 0 and MviRRXPosition = 0

    and MviRRYPosition = 0 and MviRRZPosition = 0

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/