(TRIGGER) if cell1 = 'value' THEN INSERT INTO table (date) VALUES (CURRENT_TIMESTAMP)
up vote
0
down vote
favorite
I need to create a trigger in SQL Server that triggers every time that the value from column "status" = 'Baja'
CREATE TRIGGER trg_triggerName
ON dbo.table1
AFTER UPDATE
AS
BEGIN
IF status = 'Baja' THEN BEGIN
INSERT INTO dbo.table1 (fechaBaja)
VALUES (CURRENT_TIMESTAMP)
END
END
GO
I got this error message
Msg 207, Level 16, State 1, Procedure trg_FechaBaja, Line 3 [Batch Start Line 34]
Invalid column name 'status'.
IF status = 'Baja' THEN BEGIN
In this line the "status" give me the message "invalid column name 'status'" and I'm 100% sure that my column has that name.
IN RESUME: Got a table named table1 that has a column named 'status' and another column named 'fechaBaja'
Every time that the 'status' value changes to 'Baja', I need to trigger and update the cell 'fechaBaja' with the current_timestamp
All the operations are in the same table1.
add a comment |
up vote
0
down vote
favorite
I need to create a trigger in SQL Server that triggers every time that the value from column "status" = 'Baja'
CREATE TRIGGER trg_triggerName
ON dbo.table1
AFTER UPDATE
AS
BEGIN
IF status = 'Baja' THEN BEGIN
INSERT INTO dbo.table1 (fechaBaja)
VALUES (CURRENT_TIMESTAMP)
END
END
GO
I got this error message
Msg 207, Level 16, State 1, Procedure trg_FechaBaja, Line 3 [Batch Start Line 34]
Invalid column name 'status'.
IF status = 'Baja' THEN BEGIN
In this line the "status" give me the message "invalid column name 'status'" and I'm 100% sure that my column has that name.
IN RESUME: Got a table named table1 that has a column named 'status' and another column named 'fechaBaja'
Every time that the 'status' value changes to 'Baja', I need to trigger and update the cell 'fechaBaja' with the current_timestamp
All the operations are in the same table1.
Yes you have that column, but where and which row, INSERTED table? DELETED table? Table1? You need to checkINSERTEDtable there. Please explain what are you trying to do there
– Sami
Nov 19 at 18:58
also status is a reserved word... so it's best to enclose it in brackets or not use it as a column name at all
– scsimon
Nov 19 at 19:00
hi @Sami, it is on table1, all the operation in fact. about the row, does this mean that everytime I perform this operation all the rows could be affected ?
– HiramL.
Nov 19 at 19:02
@HiramL. Since your trigger is fired AFTER UPDATE you need to checkINSERTEDtable notdbo.table1, and also you need to change you code to handle multiple rows. I suggest that you edit your question and add the DDL of your table and explain what are trying to do there
– Sami
Nov 19 at 19:06
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I need to create a trigger in SQL Server that triggers every time that the value from column "status" = 'Baja'
CREATE TRIGGER trg_triggerName
ON dbo.table1
AFTER UPDATE
AS
BEGIN
IF status = 'Baja' THEN BEGIN
INSERT INTO dbo.table1 (fechaBaja)
VALUES (CURRENT_TIMESTAMP)
END
END
GO
I got this error message
Msg 207, Level 16, State 1, Procedure trg_FechaBaja, Line 3 [Batch Start Line 34]
Invalid column name 'status'.
IF status = 'Baja' THEN BEGIN
In this line the "status" give me the message "invalid column name 'status'" and I'm 100% sure that my column has that name.
IN RESUME: Got a table named table1 that has a column named 'status' and another column named 'fechaBaja'
Every time that the 'status' value changes to 'Baja', I need to trigger and update the cell 'fechaBaja' with the current_timestamp
All the operations are in the same table1.
I need to create a trigger in SQL Server that triggers every time that the value from column "status" = 'Baja'
CREATE TRIGGER trg_triggerName
ON dbo.table1
AFTER UPDATE
AS
BEGIN
IF status = 'Baja' THEN BEGIN
INSERT INTO dbo.table1 (fechaBaja)
VALUES (CURRENT_TIMESTAMP)
END
END
GO
I got this error message
Msg 207, Level 16, State 1, Procedure trg_FechaBaja, Line 3 [Batch Start Line 34]
Invalid column name 'status'.
IF status = 'Baja' THEN BEGIN
In this line the "status" give me the message "invalid column name 'status'" and I'm 100% sure that my column has that name.
IN RESUME: Got a table named table1 that has a column named 'status' and another column named 'fechaBaja'
Every time that the 'status' value changes to 'Baja', I need to trigger and update the cell 'fechaBaja' with the current_timestamp
All the operations are in the same table1.
edited Nov 19 at 19:36
marc_s
568k12810991249
568k12810991249
asked Nov 19 at 18:55
HiramL.
54
54
Yes you have that column, but where and which row, INSERTED table? DELETED table? Table1? You need to checkINSERTEDtable there. Please explain what are you trying to do there
– Sami
Nov 19 at 18:58
also status is a reserved word... so it's best to enclose it in brackets or not use it as a column name at all
– scsimon
Nov 19 at 19:00
hi @Sami, it is on table1, all the operation in fact. about the row, does this mean that everytime I perform this operation all the rows could be affected ?
– HiramL.
Nov 19 at 19:02
@HiramL. Since your trigger is fired AFTER UPDATE you need to checkINSERTEDtable notdbo.table1, and also you need to change you code to handle multiple rows. I suggest that you edit your question and add the DDL of your table and explain what are trying to do there
– Sami
Nov 19 at 19:06
add a comment |
Yes you have that column, but where and which row, INSERTED table? DELETED table? Table1? You need to checkINSERTEDtable there. Please explain what are you trying to do there
– Sami
Nov 19 at 18:58
also status is a reserved word... so it's best to enclose it in brackets or not use it as a column name at all
– scsimon
Nov 19 at 19:00
hi @Sami, it is on table1, all the operation in fact. about the row, does this mean that everytime I perform this operation all the rows could be affected ?
– HiramL.
Nov 19 at 19:02
@HiramL. Since your trigger is fired AFTER UPDATE you need to checkINSERTEDtable notdbo.table1, and also you need to change you code to handle multiple rows. I suggest that you edit your question and add the DDL of your table and explain what are trying to do there
– Sami
Nov 19 at 19:06
Yes you have that column, but where and which row, INSERTED table? DELETED table? Table1? You need to check
INSERTED table there. Please explain what are you trying to do there– Sami
Nov 19 at 18:58
Yes you have that column, but where and which row, INSERTED table? DELETED table? Table1? You need to check
INSERTED table there. Please explain what are you trying to do there– Sami
Nov 19 at 18:58
also status is a reserved word... so it's best to enclose it in brackets or not use it as a column name at all
– scsimon
Nov 19 at 19:00
also status is a reserved word... so it's best to enclose it in brackets or not use it as a column name at all
– scsimon
Nov 19 at 19:00
hi @Sami, it is on table1, all the operation in fact. about the row, does this mean that everytime I perform this operation all the rows could be affected ?
– HiramL.
Nov 19 at 19:02
hi @Sami, it is on table1, all the operation in fact. about the row, does this mean that everytime I perform this operation all the rows could be affected ?
– HiramL.
Nov 19 at 19:02
@HiramL. Since your trigger is fired AFTER UPDATE you need to check
INSERTED table not dbo.table1, and also you need to change you code to handle multiple rows. I suggest that you edit your question and add the DDL of your table and explain what are trying to do there– Sami
Nov 19 at 19:06
@HiramL. Since your trigger is fired AFTER UPDATE you need to check
INSERTED table not dbo.table1, and also you need to change you code to handle multiple rows. I suggest that you edit your question and add the DDL of your table and explain what are trying to do there– Sami
Nov 19 at 19:06
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
accepted
I believe you want to update fechaBaja field if updated row status field equal'Baja'. You need to capture primary key information as well. I put 'Id' but you need to change it with your actuel field name.
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE dbo.table1 SET fechaBaja=CURRENT_TIMESTAMP
WHERE EXISTS (SELECT 1 FROM INSERTED I WHERE dbo.table1.Id = I.Id AND I.Status='Baja')
END
GO
3
What if there is more than one (1) row updated??
– Sami
Nov 19 at 19:10
you are right @Sami. I have updated the trigger to cover multiple update.
– Zeki Gumus
Nov 19 at 19:15
@ZekiGumus thank you for your help, this TRIGGER works perfectly, now I'm having trouble because I have another AFTER UPDATE trigger for this table that affects other column, but thanks man, this was I was looking for
– HiramL.
Nov 19 at 19:32
add a comment |
up vote
1
down vote
First, you want an update, not an insert.
Second, A trigger in SQL Server is fired once per statement, not once per row. This means that if the update statement that fired the trigger have updated multiple rows, your trigger will be fired once, and include data about these rows in the inserted and deleted tables.
Third, You need to make sure that the update statement inside the trigger will not raise it again. Do that by configuring the database.
The code you need is something like this:
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE t
SET fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 As T
INNER JOIN Inserted As I
ON T.<PrimaryKey> = I.<PrimaryKey>
INNER JOIN Deleted As D
ON T.<PrimaryKey> = D.<PrimaryKey>
WHERE I.[status] = 'Baja'
AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
END
GO
You miss)there.AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
– Sami
Nov 19 at 19:34
@sami thanks!..
– Zohar Peled
Nov 19 at 19:47
add a comment |
up vote
0
down vote
You can do it by joining the three tables like
CREATE TRIGGER trg_triggerName ON dbo.table1 AFTER UPDATE AS
BEGIN
UPDATE T1
SET T1.fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 T1 INNER JOIN INSERTED T2 ON T1.ID = T2.ID
INNER JOIN DELETED T3 ON T1.ID = T3.ID
WHERE T2.[status] = 'Baja'
AND
(T3.[status] <> 'Baja' OR T3.[status] IS NULL);
END
GO
- There is no need to use
IF.
statusis a reserved word, enclose it in brackets.- Join your table with
INSERTEDtable to get all theIDs of the rows updated. - Join your table with
DELETEDtable to get all theIDs where the data is not'Baja'. - Filter by where
INSERTED.[status] = 'Baja' AND DELETED.[status] <> 'Baja'to update only those rows.
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I believe you want to update fechaBaja field if updated row status field equal'Baja'. You need to capture primary key information as well. I put 'Id' but you need to change it with your actuel field name.
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE dbo.table1 SET fechaBaja=CURRENT_TIMESTAMP
WHERE EXISTS (SELECT 1 FROM INSERTED I WHERE dbo.table1.Id = I.Id AND I.Status='Baja')
END
GO
3
What if there is more than one (1) row updated??
– Sami
Nov 19 at 19:10
you are right @Sami. I have updated the trigger to cover multiple update.
– Zeki Gumus
Nov 19 at 19:15
@ZekiGumus thank you for your help, this TRIGGER works perfectly, now I'm having trouble because I have another AFTER UPDATE trigger for this table that affects other column, but thanks man, this was I was looking for
– HiramL.
Nov 19 at 19:32
add a comment |
up vote
0
down vote
accepted
I believe you want to update fechaBaja field if updated row status field equal'Baja'. You need to capture primary key information as well. I put 'Id' but you need to change it with your actuel field name.
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE dbo.table1 SET fechaBaja=CURRENT_TIMESTAMP
WHERE EXISTS (SELECT 1 FROM INSERTED I WHERE dbo.table1.Id = I.Id AND I.Status='Baja')
END
GO
3
What if there is more than one (1) row updated??
– Sami
Nov 19 at 19:10
you are right @Sami. I have updated the trigger to cover multiple update.
– Zeki Gumus
Nov 19 at 19:15
@ZekiGumus thank you for your help, this TRIGGER works perfectly, now I'm having trouble because I have another AFTER UPDATE trigger for this table that affects other column, but thanks man, this was I was looking for
– HiramL.
Nov 19 at 19:32
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I believe you want to update fechaBaja field if updated row status field equal'Baja'. You need to capture primary key information as well. I put 'Id' but you need to change it with your actuel field name.
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE dbo.table1 SET fechaBaja=CURRENT_TIMESTAMP
WHERE EXISTS (SELECT 1 FROM INSERTED I WHERE dbo.table1.Id = I.Id AND I.Status='Baja')
END
GO
I believe you want to update fechaBaja field if updated row status field equal'Baja'. You need to capture primary key information as well. I put 'Id' but you need to change it with your actuel field name.
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE dbo.table1 SET fechaBaja=CURRENT_TIMESTAMP
WHERE EXISTS (SELECT 1 FROM INSERTED I WHERE dbo.table1.Id = I.Id AND I.Status='Baja')
END
GO
edited Nov 19 at 19:14
answered Nov 19 at 19:08
Zeki Gumus
1,033111
1,033111
3
What if there is more than one (1) row updated??
– Sami
Nov 19 at 19:10
you are right @Sami. I have updated the trigger to cover multiple update.
– Zeki Gumus
Nov 19 at 19:15
@ZekiGumus thank you for your help, this TRIGGER works perfectly, now I'm having trouble because I have another AFTER UPDATE trigger for this table that affects other column, but thanks man, this was I was looking for
– HiramL.
Nov 19 at 19:32
add a comment |
3
What if there is more than one (1) row updated??
– Sami
Nov 19 at 19:10
you are right @Sami. I have updated the trigger to cover multiple update.
– Zeki Gumus
Nov 19 at 19:15
@ZekiGumus thank you for your help, this TRIGGER works perfectly, now I'm having trouble because I have another AFTER UPDATE trigger for this table that affects other column, but thanks man, this was I was looking for
– HiramL.
Nov 19 at 19:32
3
3
What if there is more than one (1) row updated??
– Sami
Nov 19 at 19:10
What if there is more than one (1) row updated??
– Sami
Nov 19 at 19:10
you are right @Sami. I have updated the trigger to cover multiple update.
– Zeki Gumus
Nov 19 at 19:15
you are right @Sami. I have updated the trigger to cover multiple update.
– Zeki Gumus
Nov 19 at 19:15
@ZekiGumus thank you for your help, this TRIGGER works perfectly, now I'm having trouble because I have another AFTER UPDATE trigger for this table that affects other column, but thanks man, this was I was looking for
– HiramL.
Nov 19 at 19:32
@ZekiGumus thank you for your help, this TRIGGER works perfectly, now I'm having trouble because I have another AFTER UPDATE trigger for this table that affects other column, but thanks man, this was I was looking for
– HiramL.
Nov 19 at 19:32
add a comment |
up vote
1
down vote
First, you want an update, not an insert.
Second, A trigger in SQL Server is fired once per statement, not once per row. This means that if the update statement that fired the trigger have updated multiple rows, your trigger will be fired once, and include data about these rows in the inserted and deleted tables.
Third, You need to make sure that the update statement inside the trigger will not raise it again. Do that by configuring the database.
The code you need is something like this:
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE t
SET fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 As T
INNER JOIN Inserted As I
ON T.<PrimaryKey> = I.<PrimaryKey>
INNER JOIN Deleted As D
ON T.<PrimaryKey> = D.<PrimaryKey>
WHERE I.[status] = 'Baja'
AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
END
GO
You miss)there.AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
– Sami
Nov 19 at 19:34
@sami thanks!..
– Zohar Peled
Nov 19 at 19:47
add a comment |
up vote
1
down vote
First, you want an update, not an insert.
Second, A trigger in SQL Server is fired once per statement, not once per row. This means that if the update statement that fired the trigger have updated multiple rows, your trigger will be fired once, and include data about these rows in the inserted and deleted tables.
Third, You need to make sure that the update statement inside the trigger will not raise it again. Do that by configuring the database.
The code you need is something like this:
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE t
SET fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 As T
INNER JOIN Inserted As I
ON T.<PrimaryKey> = I.<PrimaryKey>
INNER JOIN Deleted As D
ON T.<PrimaryKey> = D.<PrimaryKey>
WHERE I.[status] = 'Baja'
AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
END
GO
You miss)there.AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
– Sami
Nov 19 at 19:34
@sami thanks!..
– Zohar Peled
Nov 19 at 19:47
add a comment |
up vote
1
down vote
up vote
1
down vote
First, you want an update, not an insert.
Second, A trigger in SQL Server is fired once per statement, not once per row. This means that if the update statement that fired the trigger have updated multiple rows, your trigger will be fired once, and include data about these rows in the inserted and deleted tables.
Third, You need to make sure that the update statement inside the trigger will not raise it again. Do that by configuring the database.
The code you need is something like this:
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE t
SET fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 As T
INNER JOIN Inserted As I
ON T.<PrimaryKey> = I.<PrimaryKey>
INNER JOIN Deleted As D
ON T.<PrimaryKey> = D.<PrimaryKey>
WHERE I.[status] = 'Baja'
AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
END
GO
First, you want an update, not an insert.
Second, A trigger in SQL Server is fired once per statement, not once per row. This means that if the update statement that fired the trigger have updated multiple rows, your trigger will be fired once, and include data about these rows in the inserted and deleted tables.
Third, You need to make sure that the update statement inside the trigger will not raise it again. Do that by configuring the database.
The code you need is something like this:
CREATE TRIGGER trg_triggerName ON dbo.table1
AFTER UPDATE AS
BEGIN
UPDATE t
SET fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 As T
INNER JOIN Inserted As I
ON T.<PrimaryKey> = I.<PrimaryKey>
INNER JOIN Deleted As D
ON T.<PrimaryKey> = D.<PrimaryKey>
WHERE I.[status] = 'Baja'
AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
END
GO
edited Nov 19 at 19:47
answered Nov 19 at 19:16
Zohar Peled
51.9k73173
51.9k73173
You miss)there.AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
– Sami
Nov 19 at 19:34
@sami thanks!..
– Zohar Peled
Nov 19 at 19:47
add a comment |
You miss)there.AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')
– Sami
Nov 19 at 19:34
@sami thanks!..
– Zohar Peled
Nov 19 at 19:47
You miss
) there. AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')– Sami
Nov 19 at 19:34
You miss
) there. AND (D.[Status] IS NULL OR D.[Status] <> 'Baja')– Sami
Nov 19 at 19:34
@sami thanks!..
– Zohar Peled
Nov 19 at 19:47
@sami thanks!..
– Zohar Peled
Nov 19 at 19:47
add a comment |
up vote
0
down vote
You can do it by joining the three tables like
CREATE TRIGGER trg_triggerName ON dbo.table1 AFTER UPDATE AS
BEGIN
UPDATE T1
SET T1.fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 T1 INNER JOIN INSERTED T2 ON T1.ID = T2.ID
INNER JOIN DELETED T3 ON T1.ID = T3.ID
WHERE T2.[status] = 'Baja'
AND
(T3.[status] <> 'Baja' OR T3.[status] IS NULL);
END
GO
- There is no need to use
IF.
statusis a reserved word, enclose it in brackets.- Join your table with
INSERTEDtable to get all theIDs of the rows updated. - Join your table with
DELETEDtable to get all theIDs where the data is not'Baja'. - Filter by where
INSERTED.[status] = 'Baja' AND DELETED.[status] <> 'Baja'to update only those rows.
add a comment |
up vote
0
down vote
You can do it by joining the three tables like
CREATE TRIGGER trg_triggerName ON dbo.table1 AFTER UPDATE AS
BEGIN
UPDATE T1
SET T1.fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 T1 INNER JOIN INSERTED T2 ON T1.ID = T2.ID
INNER JOIN DELETED T3 ON T1.ID = T3.ID
WHERE T2.[status] = 'Baja'
AND
(T3.[status] <> 'Baja' OR T3.[status] IS NULL);
END
GO
- There is no need to use
IF.
statusis a reserved word, enclose it in brackets.- Join your table with
INSERTEDtable to get all theIDs of the rows updated. - Join your table with
DELETEDtable to get all theIDs where the data is not'Baja'. - Filter by where
INSERTED.[status] = 'Baja' AND DELETED.[status] <> 'Baja'to update only those rows.
add a comment |
up vote
0
down vote
up vote
0
down vote
You can do it by joining the three tables like
CREATE TRIGGER trg_triggerName ON dbo.table1 AFTER UPDATE AS
BEGIN
UPDATE T1
SET T1.fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 T1 INNER JOIN INSERTED T2 ON T1.ID = T2.ID
INNER JOIN DELETED T3 ON T1.ID = T3.ID
WHERE T2.[status] = 'Baja'
AND
(T3.[status] <> 'Baja' OR T3.[status] IS NULL);
END
GO
- There is no need to use
IF.
statusis a reserved word, enclose it in brackets.- Join your table with
INSERTEDtable to get all theIDs of the rows updated. - Join your table with
DELETEDtable to get all theIDs where the data is not'Baja'. - Filter by where
INSERTED.[status] = 'Baja' AND DELETED.[status] <> 'Baja'to update only those rows.
You can do it by joining the three tables like
CREATE TRIGGER trg_triggerName ON dbo.table1 AFTER UPDATE AS
BEGIN
UPDATE T1
SET T1.fechaBaja = CURRENT_TIMESTAMP
FROM dbo.table1 T1 INNER JOIN INSERTED T2 ON T1.ID = T2.ID
INNER JOIN DELETED T3 ON T1.ID = T3.ID
WHERE T2.[status] = 'Baja'
AND
(T3.[status] <> 'Baja' OR T3.[status] IS NULL);
END
GO
- There is no need to use
IF.
statusis a reserved word, enclose it in brackets.- Join your table with
INSERTEDtable to get all theIDs of the rows updated. - Join your table with
DELETEDtable to get all theIDs where the data is not'Baja'. - Filter by where
INSERTED.[status] = 'Baja' AND DELETED.[status] <> 'Baja'to update only those rows.
edited Nov 19 at 19:43
answered Nov 19 at 19:14
Sami
7,08831038
7,08831038
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380978%2ftrigger-if-cell1-value-then-insert-into-table-date-values-current-times%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Yes you have that column, but where and which row, INSERTED table? DELETED table? Table1? You need to check
INSERTEDtable there. Please explain what are you trying to do there– Sami
Nov 19 at 18:58
also status is a reserved word... so it's best to enclose it in brackets or not use it as a column name at all
– scsimon
Nov 19 at 19:00
hi @Sami, it is on table1, all the operation in fact. about the row, does this mean that everytime I perform this operation all the rows could be affected ?
– HiramL.
Nov 19 at 19:02
@HiramL. Since your trigger is fired AFTER UPDATE you need to check
INSERTEDtable notdbo.table1, and also you need to change you code to handle multiple rows. I suggest that you edit your question and add the DDL of your table and explain what are trying to do there– Sami
Nov 19 at 19:06