Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good afternoon
I have a stroreprocedure that updates a column in a table when another table is changed, but when that happens it changes the volumes all referring to the table id and I didn't want that to happen, I just wanted the new records to be changed
Thank you in advance for any help you can give me

What I have tried:

SQL
<pre>USE [MiniPayroll]
GO
/****** Object:  StoredProcedure [dbo].[sp_SubMensal_update]    Script Date: 09-04-2021 15:47:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[sp_SubMensal_update]


	
AS
BEGIN
	UPDATE      EmpAttendance
SET   SubDiario = 

(
SELECT SubDiario
FROM EmpSalary
where EmpAttendance.EmpId = EmpSalary.EmpId) 

END
Posted
Updated 9-Apr-21 8:51am

1 solution

You need some way to tell which ones are in whatever you define as a 'new' state and add that to your WHERE clause when selecting records for updating. There are quite a few ways to do this, depending upon what your table looks like.

You need to be able to tell them apart and tell SQL just how you'd do it.
 
Share this answer
 
v2
Comments
miguel santos 2021 10-Apr-21 2:48am    
Thank you very much for your help, but will it be possible to give me a practical example? I'm new to this

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