[Microsoft] [odbc SQL Server Driver] [SQL Server] parameter data type text is invalid for parameter 1 of the replace function.

Source: Internet
Author: User
Tags sql server driver odbc sql server driver

When it comes to text replacement in databases, most people first think of the replace function:

Update table set column = Replace (column, 'oldkeyword', 'newkeyword ')

However, when column is text or ntext, the preceding query will return the error "Text of the parameter data type is invalid for parameter 1 of the replace function ". It turns out that string operations cannot be performed on data of the text or ntext type in queries. At this time, the most commonly used method is to treat text as varchar (when the actual content length is less than 8000 bytes) or treat ntext as nvarchar (when the actual content length is less than 4000 bytes:

Update table set column = Replace (cast (column as varchar (8000), 'oldkeyword', 'newkeyword ')

Update table set column = Replace (cast (column as nvarchar (4000), 'oldkeyword', 'newkeyword ')

Related Article

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.