Home > database >  Used to trigger to create an error big brothers
Used to trigger to create an error big brothers

Time:05-27

Description: after inserting data, when this data in time field is
The current time, modify this data field (state)
Create the trigger updateState
On [emailHis]
After INSERT
As
The begin
Declare @ state int
If the exists (SELECT id @ state, dateTime from [emailHis] WHERE a dateTime=GETDATE ())
The UPDATE [emailHis] set state=2 where id=@ state
End
Go


An error is as follows:
Msg 102, Level 15, State 1, Server WIN - TNFHCMO65GI, Procedure updateState, Line 7
"@ state near the grammatical errors,"
17 [42000] [Microsoft] [ODBC Driver for SQL Server] [SQL Server] "@ state near the grammatical errors," (102)

Time: 0.003 s

CodePudding user response:

SELECT the id @ state, dateTime from

What are you want to do

CodePudding user response:

SELECT id @ the state side there is a problem, how to modify it,,,, please

CodePudding user response:

Judgment is accurate to seconds, if you insert data is overmuch, insert the start time and end time, there will be a time lag between

You'd better put this trigger thought to realize the business logic of the description is clear, otherwise, they can only guess, or you could try the following logic is your

 
Create the trigger updateState
On [emailHis]
After INSERT
As
The begin
The UPDATE emailHis
Set the state=2
The FROM emailHis AS A
The JOIN INSERTED ON Anderson, D=B B.I D
WHERE a. d. ATETIME=the CONVERT (SMALLDATETIME, GETDATE ())
End
Go

Prev:222
  • Related