Solved

trigger fails when updating >1 row

Posted on 2012-03-12
4
279 Views
Last Modified: 2012-03-13
Why would this trigger succeed if there's only one row to be updated, but it fails if there's >1 row to be updated?

IF EXISTS (select null
      from   Appeals a INNER JOIN
         INSERTED i ON a.ParcelNo = i.ParcelNo
                AND a.TaxYear = i.TaxYear
                AND a.LValue = i.CertValue
                AND a.LAssmt = i.CertAssmt)
UPDATE Appeals SET Ruling = 'AFFIRMED'
FROM   Appeals as a INNER JOIN
             INSERTED AS i on a.ParcelNo = i.ParcelNo
            AND a.TaxYear = i.TaxYear
                                   AND a.LValue = i.CertValue
                                   AND a.LAssmt = i.CertAssmt

The error message I get is:
Subquery returned more than one value. This is not permitted when the subquery follows =, !=, etc. or when the subquery is used as an expression.

Sorry this is all text, but I can't figure out how to post code and text separately in the new EE. :(
0
Comment
Question by:GordonPrince
  • 2
4 Comments
 
LVL 4

Author Comment

by:GordonPrince
ID: 37712193
This is pretty similar, and a bit more economical. It seems to have the same behavior. I don't understand why this one fails either.

TRIGGER AFTER UPDATE OF Parcel...
-------------------------------------
UPDATE Appeals SET Ruling = 'AFFIRMED'
FROM   Appeals as a INNER JOIN
         INSERTED AS i on a.ParcelNo = i.ParcelNo
                               AND a.TaxYear = i.TaxYear                                                       AND a.LValue = i.CertValue
                   AND a.LAssmt = i.CertAssmt
WHERE Ruling IS NULL
   OR Ruling <> 'AFFIRMED'
0
 
LVL 13

Accepted Solution

by:
dwkor earned 500 total points
ID: 37712282
Do you have any triggers on Appeals table or other triggers on Parcel table?
0
 
LVL 25

Expert Comment

by:jogos
ID: 37713369
The trigger handles all updated rows at same time. The join-condition between the 'inserted' (updated rows) and the appeals table is simply not unique.

This problem occurs only when that join returns multiple records, so for another multiple record update it could be the join returns only one row per record you want to update.

Try to fake that update-join with a select-join but now not from 'inserted' (that's obvious only available in trigger) but from real table with a
WHERE PK in ([list of PK's of updated records])

Other possibility To debug create a table that can contain the result of the join and replace the updat in your trigger with to insert the records to that table and do your update again, then analyse why the join returns to much.
 


PS to make a EE code-bloc click on 'code' in the menu just on top of the textbox you are tiyping in.
0
 
LVL 4

Author Comment

by:GordonPrince
ID: 37714745
The error was being caused by another trigger on the Appeals table. From my application it was just showing me the error. When I ran update statements from SQL Management Console I could see the name of the trigger that was causing the trouble. Good thinking. Thanks.

PS: I found out there's an issue with EE and IE9, for which EE has posted a fix.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now