Click here to Skip to main content
15,894,955 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi all,

I'm new to SQL Database.
I'm now extending existing project with MS SQL server 2005.
The problem is that.
There is one existing table called: tblWorkerCertification
I'm now creating new table called: tblCourseParticipant
Bcoz of existing table and modules, I wasn't allowed to change the existing table and columns.
After the user assign the worker into course, I update table tblCourseParticipant and
I also need to insert new record into tblWorkerCertification.
We already have existing stored proc to insert new record for tblWorkerCertification called: tblWorkerCertificatipn_Sp_Insert.
So, I'm writing my stored proc to update tblCourseParticipant and
During my update process, I need to call existing tblWorkerCertificatipn_Sp_Insert stored procedure.

SQL
UPDATE  tblCPar
                SET
                        [CourseScheduleID]  = @pBIntCourseScheduleID,
                        [IsApproved]        =   @pBitIsApprove,
                        [ApprovedDate]      =   GETDATE(),
                        [ApprovedBy]        =   @pIntApprovedBy
                FROM    tblCourseParticipant tblCPar
                INNER   JOIN
                        @pXmlParticipantList.nodes ('/ParticipantList/Participant') XParTbl(XParRow)
                ON      tblCPar.[ParticipantID] = XParRow.value('@ParticipantID', 'BIGINT')
                WHERE   tblCPar.[Status] <> @pBitIsApprove



This is my stored proc for updating the tblCourseParticipant, all the selected workers will be sent with XML format. including their ID.

Where should I called this and How can I do it without using Loop?
Posted
Updated 21-Mar-11 17:07pm
v2

1 solution

You can use a TRIGGER to achieve this kind of goal. There are plenty of tutorials out there on how to use it effectively.
 
Share this answer
 
Comments
ktrrzn 22-Mar-11 0:23am    
Hi walterhevedeich,

How can I do this TRIGGER? In which table? in new table or in existing table?
I'm not sure but TRIGGER don't accept parameter input, right?
I need to pass parameters to execute my existing stored proc..

Thank you
walterhevedeich 22-Mar-11 6:29am    
Yes you are correct. Triggers dont accept parameters. Some questions though. What are the parameters of your insert sp on your old table? where will the data come from? If the data that you are updating on the new table are the same data that you will insert on the old one, then a trigger can be a solution, and I may be able to help you with it. Otherwise, we may need to try a different approach.
ktrrzn 22-Mar-11 19:49pm    
the old insert sp accept 7 parameters and some of them are depend on the XML input parameter of new sp.
Like: grade, skilllevel, result. these will be passed from my new sp to old sp to insert the new record.
the xml will contain info of many participants.
For my new sp, i can handle this XML format for multiple update process.
But for old one, it is designed only for one insert
So, I m thinking whether i copy all the insert process from old one and combine with my new sp
to do all the thing.
But I'm not sure this is a good way.
Could u plz guide me on this..

Thank you
walterhevedeich 25-Mar-11 16:13pm    
Well.. What you can do is to try first on your dev environment using a test data. If the performance is acceptable, then you may try considering it as a solution. If not, you may want to post your sp here and some details for me to help you. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900