home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,591 of 19,505   
   Erland Sommarskog to EJO   
   Re: trigger help   
   28 Jul 09 19:58:44   
   
   38aaf226   
   From: esquel@sommarskog.se   
      
   EJO (myd0j0@gmail.com) writes:   
   > In sql server 2000 i'm working with my first trigger and it is giving   
   > me a bit of trouble.  I believe these are coded correctly, but can't   
   > seem to figure out what the problem is; the only items that appear to   
   > work without fail are the 'if update(cancelled)' and 'if update   
   > (billed)' statements; billed and cancelled are bit datatypes and the   
   > other 3 are datetime datatypes.  The updates are typically made   
   > through an asp.net page, but other than the billed and cancelled   
   > fields being updated, cannot seem to get the trigger to fire.  Trigger   
   > sql:   
      
   Without data to test, or a repro script that shows the entire issue   
   it is difficult to tell, but this caught my eye:   
      
   > if update(Accept_Act)   
   >      Begin   
   >   
   >                Update dbo.SR   
   >                Set dbo.SR.FinalPrice_Plan = dateadd(day, 2, getdate())   
   >                Where dbo.SR.ID   
   >                     IN (Select i.ID from inserted i inner join deleted d   
   >                     on i.id =   
   > d.id and i.Accept_Act <> d.Accept_Act)   
   >      End   
      
   If you update from NULL to a value or the other way around, this UPDATE   
   will not hit any rows, because comparisons with NULL yields UNKNOWN.   
   You may need   
      
       AND (i.Accept_Act <> d.Accept_Act OR   
            i.Accept_Act IS NULL AND d.Accept_Act IS NOT NULL OR   
            i.Accept_Act IS NOT NULL AND d.Accept_Act IS NULL)   
      
      
   --   
   Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se   
      
   Links for SQL   
   Server Books Online:   
   SQL 2008:   
   http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx   
   SQL 2005:   
   http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx   
   SQL 2000:   
   http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca