Solved

SQL Trigger on Insert to Update another table

Posted on 2009-04-03
1
191 Views
Last Modified: 2012-05-06
I have a table called CASES
And I would like that when a case is inserted with case_incidenttype = 'INAFP'
That it updates a field called COMP_AFPSCONSUMED in a table called COMPANY by adding an incremental number, I have included the join below

CASES
case_primarycompanyid         case_incidenttpye        
101                                           INAFP

COMPANY
comp_companyid                    comp_afpsconsumed
101                                           2 (+1 when a case is inserted with type INAPF)


0
Comment
Question by:MimUK
1 Comment
 

Accepted Solution

by:
MimUK earned 0 total points
ID: 24058615
update Company
  set comp_afpsconsumed =
    (select count(case_caseid)
     from Cases ca
     where ca.case_primarycompanyid = company.comp_companyid and ca.case_deleted is null and ca.case_incidenttype = 'INAFP')
  where comp_companyid in
    (select case_primarycompanyid from inserted
     union
     select case_primarycompanyid from deleted);
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sql query 12 65
How to check data in sql table 11 38
sql help 5 49
Bubble user-defined Sql RAISERROR(...) to c# exception 14 118
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will useā€¦
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now