Hi All,I have two tables in a database and need to create a trigger after update on one table so that it updates another. may u pliz help me with this problem I have.
8 1289
Hi MandlaT,
Welcome to the scripts!! I will move this ost to the SQL forum for you. In future you can post there directly, by selecting the SQL forum from the "Forums" tab on the blus bar at the top of your screen.
I hope you find the information you need!
Thanks! I look forward to getting replies.
Hi Mandla,
You can have the following syntax for the trigger -
create trigger trigger_name on table1
-
after update
-
as
-
begin
-
update table2 set col=<new value> [where <condition>];
-
end
-
Hope this helps
Cheers
Thanks, will let you know about the outcome.
Thanks, It worked but I'm getting duplicate values. how can I solve the problem?
Thanks, It worked but I'm getting duplicate values. how can I solve the problem?
Hi,
Can you give more input. May be the update statement you are using or the trigger
Cheers
Hi Thanks for answering me,
when there is an update on dstParameters it should set the trigger to update dstControlData. but am getting duplicate values. It should only accept different values on the date eg 200704 or 200705 on [dstYearMonth].
-- =============================================
-- Author: User
-- Create date: 17/05/2007
-- Description: Updating
-- =============================================
ALTER TRIGGER .[dbo].[updateData]
ON .[dbo].[dstSalesParameters]
AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--DECLARE @data XML;
DECLARE @distributer nvarchar(15);
DECLARE @salesPeriod int;
DECLARE @salesRec int;
DECLARE @customerRec int;
DECLARE @materialRec int;
DECLARE @callSheetRec int;
DECLARE @importPriceRec int;
DECLARE @extractPriceRec int;
DECLARE @extractEquipRec int;
SET @distributer = (SELECT dstDistributer FROM inserted);
SET @salesPeriod = (SELECT SalesPeriod FROM inserted);
SET @salesRec = (SELECT ExtractSaleRec FROM inserted);
SET @customerRec = (SELECT ExtractCustomerRec FROM inserted);
SET @materialRec = (SELECT ExtractMaterialRec FROM inserted);
SET @callSheetRec = (SELECT ExtractCallSheetRec FROM inserted);
SET @importPriceRec= (SELECT ImportPriceRec FROM inserted);
SET @extractPriceRec = (SELECT ExtractPriceRec FROM inserted);
SET @extractEquipRec = (SELECT ExtractEquipmentRec FROM inserted)
--FROM dstSalesParameters
INSERT [dbo].[dstControlData]
(
--[dstControlID],
[dstAgentCode],
dstYearMonth,
dstSalesRec,
dstCustomerRec,
dstMaterialRec,
dstCallSheetRec,
dstIPriceRec,
dstEPriceRec,
dstEquipmentRec
)
VALUES
(
@distributer,
@salesPeriod,
@salesRec,
@customerRec,
@materialRec,
@callSheetRec,
@importPriceRec,
@extractPriceRec,
@extractEquipRec
);
END
Dear MandlaT,
I am not totally clear what you're asking but maybe you want to do a select on dstControl for the Yeardate you are about to insert so that you do so only if it doesnot exist.
Regards
MakingDBA
Sign in to post your reply or Sign up for a free account.
Similar topics
by: serge |
last post by:
How can i delete all user stored procedures and all table triggers very fast
in
a single database?
Thank you
|
by: Manish Bafna |
last post by:
speaking of me, I'm not very new to Access, but I haven't worked on it
as a professional.
I know that you can fire queries in Access, but I don't think you can
create views.
i want to know that...
|
by: jagdpenta |
last post by:
This is my second post
What are the advantages of stored procedures, triggers, indexes
E-Mail address blocked: See forum rules - moderator
Thanks in advance
|
by: Miaaa Mukherjee |
last post by:
Hello,
I want to know something about the stored procedures and triggers which are used.
I want to know that the procedures n triggers r created in SQL Server 2005 or...
|
by: FP |
last post by:
Hi,
i have read that with Visual Studio 2005 it's possible to create stored
procedures and triggers for a Sql Server 2005 database.
I must admit that i have already written the stored procedures...
|
by: cvraghavan1979 |
last post by:
Hi guys,
let me know the difference between the use of direct queries and the stored procedures / Triggers. also pls specify the advantages of using the stored procedures / triggers....
|
by: sonia.sardana |
last post by:
Hey can anyone tell me whether Triggers and Stored Procedures are same?
Triggers are stored procedures that get executed automatically when an Insert,Update,or Delete operation takes place.
...
|
by: --CELKO-- |
last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any
kind of tools for this?
|
by: anuragshrivastava64 |
last post by:
I am new to SQL Server.
I have got a project where lot of stored procedures ,UDF's and triggers are used.
The problem is I am finding all the functions and procedures but not been able to find any...
|
by: ajaysbedi |
last post by:
Hi,
I have 2 triggers on a table, both triggers are updating the another table
create trigger DB.TRG1 AFTER INSERT ON Table1REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL WHEN ( NEW.DEPT <>...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |