Usage of SQL string function stuff

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.