Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Trigger is Updating random row not the joined row
    primarykey
    data
    text
    <p>I have this query in a update trigger</p> <pre><code>UPDATE [FSSQLPROD01].[collectionsDELETE].[dbo].[collections] SET Defendant_1 = i.DisplayName , Loan_Number_1 = i.Comments , Client = i.KS_BookName , Date_Instructed = i.OpenDate , Person_Responsible_name = i.ResponsibleFeeEarnerName , Person_Responsible_Email = i.ResponsibleFeeEarnerEmail , Person_Acting_name = i.BillingFeeEarnerName , Person_Acting_email = i.BillingFeeEarnerEmail , Agent_Acting_name = i.BillingFeeEarnerName , Agent_Acting_email = i.BillingFeeEarnerEmail , CBA_Panel_Service_Area = i.KS_ServiceCat , HBN_Number = i.KS_ClientAcctRef , St_George_Contact = i.KS_Instructor FROM [FSSQLPROD01].[collectionsDELETE].[dbo].[collections] c INNER JOIN Inserted i ON Left(c.file_number, 6) COLLATE DATABASE_DEFAULT = i.MatterNumber COLLATE DATABASE_DEFAULT </code></pre> <p><img src="https://i.stack.imgur.com/cjJ1P.jpg" alt="enter image description here"> Now the Join connection matches up on the File_Number e.g. 70003-1 but for some unknown reason the data that should be updated to this Row is been updated to a toally random row 614864-7 </p> <p>I can continue to execute the trigger and tring to update the 70003-1 row but i continues to update the other row 614864-7 </p> <p>This is also running across a linked server the trigger is on one server up dating the other servers</p> <p>Server tigger sits on Microsoft SQL Server 2005 - 9.00.3042.00 (X64) Feb 10 2007 00:59:02 Copyright (c) 1988-2005 Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2) </p> <p>Server trigger is updating Microsoft SQL Server 2005 - 9.00.3042.00 (X64) Feb 10 2007 00:59:02 Copyright (c) 1988-2005 Microsoft Corporation Enterprise Edition (64-bit) on Windows NT 5.2 (Build 3790: Service Pack 2) </p> <p>I have been thinking that updating the servers SP to SP4 may fix the problem?</p> <p>Does anyone have a reson why this might be haapening the Server </p> <p>Ammendment </p> <p>Yeah i actually hardcoded the values and simplified the SQL Statement it works as it should </p> <pre><code>DECLARE @MatterNumber as varchar(50) SET @MatterNumber = (SELECT i.MAtternumber FRom Inserted as i) + '-1' Print @MatterNumber UPDATE [FSSQLPROD01].[collectionsDELETE].[dbo].[collections] SET Loan_Number_1 = ‘123’ WHERE file_number = @MatterNumber </code></pre> <p>But as soon as I set a Declared Varible value to Loan_Number_1 or any of the other columes this is when the problem starts to happen</p> <pre><code>DECLARE @LoanNumber as varchar(50) SET @LoanNumber = (SELECT i.Comments FRom Inserted as i) Print @LoanNumber DECLARE @MatterNumber as varchar(50) SET @MatterNumber = (SELECT i.MAtternumber FRom Inserted as i) + '-1' Print @MatterNumber –-I print here I see 70003-1 UPDATE [FSSQLPROD01].[collectionsDELETE].[dbo].[collections] SET Loan_Number_1 = @LoanNumber WHERE file_number = @MatterNumber Print @MatterNumber –-I print here I see 70003-1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload