Solved

trigger fails when updating >1 row

Posted on 2012-03-12
4
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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