SQL SERVER uses REPLACE to REPLACE a value in a field in a column with another value. sqlreplace

Source: Internet
Author: User

SQL SERVER uses REPLACE to REPLACE a value in a field in a column with another value. sqlreplace

SQL SERVER replaces a value in a field with another value.
Update table name set column name = REPLACE (column name, 'A', 'bb ')

SQL SERVER "the Data Type of parameter 1 of function replace is invalid ntext" SOLUTION

UPDATE table name SET column name = REPLACE (CAST column name AS varchar (8000), 'A', 'bb ')


How to replace a value in a column field with another value in SQL SERVER 2008 database?

Use replace. The core idea is to replace ', 1,' with ', 11,12, 13,14, 15,16 ,'. Considering that 1 may appear at the beginning or end, add a comma at the beginning and end of the original string. In this way, you can replace them all. After replacement, remove the start and end commas.
Create table v (VHCL_RANGE_CODE varchar (100); insert into v select '8, 22, 41 'Union allselect' 8, 1, 3, 21 'Union allselect' 1, 22, 'Union allselect' 3, 6, 1 '-- add this article to test the situation at the end of 1 -- add a comma before and after each, replace update v set VHCL_RANGE_CODE = replace (', '+ VHCL_RANGE_CODE + ',',', 1, ',', 11,12, 13,14, 15,16, '); -- remove the comma before and after update v set VHCL_RANGE_CODE = substring (VHCL_RANGE_CODE, 2, len (VHCL_RANGE_CODE)-2) result After replacement:




Replace a value in a field with an SQL statement.

Check that your database is accessible.
SQL server
Update a set x = REPLACE (x, 'A', 'B ');

Hypothesis:
X Original content is ababababab
After execution, it becomes bbbbbbbbbb.

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.