MSSQL error: the parameter data type text is invalid for parameter 1 of the replace function.

Source: Internet
Author: User
Tags microsoft sql server 2005

But we can solve this problem in another way. Next we will analyze the solution.

String operations cannot be performed on text or ntext data in queries. In this case, the most commonly used method is to treat text as varchar (when the actual content length is less than 8000 bytes) or ntext as nvarchar (when the actual content length is less than 4000 bytes. However, this is not very appropriate. After all, if the content of the text field exceeds 8000, it is not necessary to be truncated or ignored.
Finally, we found a way to solve the problem of "parameter data type text is invalid for parameter 1 of the replace function. The following example shows how to handle the problem.
Syntax:
Copy codeThe Code is as follows: update table set column = replace (cast (column as varchar (max), '123', 'abc ')
Explanation:
The table indicates the table name. column code indicates the columns to be replaced in the table. The statement is used to replace 123 of all columns in the column of the table with abc.
Appendix: Introduction to the max type
The max specifier is introduced in Microsoft SQL Server 2005. This specifier enhances the storage capability of varchar, nvarchar, and varbinary data types. Varchar (max), nvarchar (max), and varbinary (max) are collectively referred to as big data types. You can use the bytes data type to store data up to 2 ^ 31-1 bytes.
Note:
When the 'large value types out of row' option of the sp_tableoption stored procedure is set to OFF, the bytes-type in-row Storage is limited to 8000 bytes. When this option is set to ON, only the 16-byte root is stored in the row. For more information, see sp_tableoption (Transact-SQL ).
The behavior of the primary data type is similar to that of varchar, nvarchar, and varbinary. This similarity enables SQL Server to more efficiently store and retrieve large characters, Unicode, and binary data.
With the timeline data type, the SQL Server method is impossible to use the text, ntext, and image data types in earlier versions of SQL Server. For example, in SQL Server 2005, you can define variables that can store a large amount of data (up to 2 ^ 31 bytes of characters, integers, and Unicode data. For more information, see Transact-SQL variables.
The following table describes the relationship between the volume data type and the corresponding data type in earlier versions of SQL Server.

Shard Data Type LOB in earlier versions
Varchar (max) Text *
Nvarchar (max) Ntext *
Varbinary (max)

Image

* SQL Server 6.5 clients do not support ntext data types, so nvarchar (max) cannot be identified ).


Important:
Use varchar (max), nvarchar (max), and varbinary (max) Data Types instead of text, ntext, and image data types.
The behavior of the primary data type is the same as that of the smaller data types varchar (n), nvarchar (n), and varbinary (n. The following describes how to use the sequence data type in certain situations:
Since the cursor data type variable can be defined, you can assign the data in the lifecycle data type column returned by FETCH to the local variable. For more information, see FETCH (Transact-SQL ). The use of the cursor data type does not affect the forced Implementation of the cursor type conversion usage.
The block UPDATE statement currently supports partial UPDATE of the basic shard data column by the. WRITE () clause. This is similar to text pointer operations, WRITETEXT, and UPDATETEX for text, ntext, and image data types supported in earlier versions of SQL Server. For more information, see UPDATE (Transact-SQL ). The trigger supports the use of the AFTER trigger for reference to the values data type columns in the inserted and deleted tables. For more information, see create trigger (Transact-SQL ).
The built-in string functions that can operate on characters and binary data are enhanced. They support parameters of the bytes data type. These functions include:
Copy codeThe Code is as follows: COL_LENGTH
CHARINDEX
PATINDEX
LEN
DATALENGTH
SUBSTRING

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.