Yesterday, a server accidentally encountered an error. As a result, a batch of abnormal data was generated. You need to find a way to correct the date values contained in some fields. One of them uses a function called stuff, it is mainly used to replace the value of a part of a string. The SQL statement is as follows:
Update BCS set [date_scan] = stuff ([date_scan], 6,1, '5'), [date_in] = stuff (convert (varchar, [date_in], 120), 7,1, '5'), [Day] = stuff ([Day], 6,1, '5') where ID> 1160244 and [Day] = '123'
The usage of stuff is relatively simple. 1st parameters are field names, 2nd parameters are the starting position, 3rd parameters are the length, and 4th parameters are the characters to be replaced.
Here we will talk about the date_in field. This field is in the date format. You must use the convert function to convert it to the converted type in the specified format, and then apply the stuff function. Otherwise, the replacement result is inconsistent with the Expected One.
Because many applications take the server time, this time is very important and must always check the accuracy of this time.