0

This is my example code:

create trigger MyTrigger on myTable
after update
as
begin
   set nocount on;
   update talleres set status='active' where FirstDate=getdate()
end
go


create trigger MyTrigge2 on MyTable
for update
as
begin
   declare @d DATETIME=getdate();
   set nocount on;
   update talleres set status='Active' where FirstDate=format(@d,'MM/dd/YYYY')
end
go
  • What data type is FirstDate? – McNets Jan 11 at 14:20
3

Please consider creating a minimal, complete, and verifiable example for this and any future questions you create. As it is, your question is extremely imprecise and open to a lot of interpretation about what the actual problem is you are trying to solve.

Aside from that, there are several issues I see immediately.

SQL Server DML triggers use the "special" virtual tables, inserted and deleted, as placeholders containing the rows that will have been modified. You should use them in your statements to only update the affected rows. Microsoft Docs has a great article about that here.

An example for your first trigger:

create trigger MyTrigger on myTable
after update
as
begin
   set nocount on;
   update talleres 
   from talleres t inner join inserted i on t.talleres_id = i.talleres_id
   set status='active' 
   where FirstDate=getdate()
end
go

In the above example, I'm assuming you have a column that uniquely identifies rows in the talleres table and the MyTable table.

The WHERE firstdate = getdate() construct is likely going to be problematic since getdate() returns a very precise value that is perhaps unlikely to match any rows in talleres.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.