Sqlserver replace Function

Source: Internet
Author: User

Syntax
REPLACE ('string _ e-xpression1', 'string _ e-xpression2', 'string _ e-xpression3 ')
Parameter description
'String _ e-xpression1'
String expression to be searched. String_e-xpression1 can be character data or binary data.
'String _ e-xpression2'
String expression to be searched. String_e-xpression2 can be character data or binary data.
'String _ e-xpression3'
String expression used for replacement. String_e-xpression3 can be character data or binary data.

The format is as follows:
Update table name SET column to be replaced = REPLACE (the column to be replaced, the character to be replaced, and the character to be replaced)
Example SQL statement:
Update tableName SET columeName = REPLACE (columeName, 'A', 'B ')

However, it is worth noting that SQL Server has a replace function that can be used directly. The replace function of the Access database can only be used in the Access environment and cannot be used in Jet SQL, so it is useless to ASP, when you call this function in ASP, an error is displayed: The 'replace 'function in the expression is not defined. You can write a function in Asp to implement this function.
Example function:
Copy codeThe Code is as follows:
Function replace (title)
{
Replace (title, 'aaa', 'bbbbbb ')
Return (title)
}
Bbb = replace (title)
Update... set title = '"& bbb &"'

Reference code for ASP + access batch replacement of specified characters:
Copy codeThe Code is as follows:
<%
Set Conn = Server. CreateObject ("ADODB. Connection ")
Conn. Open "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("database name. mdb ")
Set rs = Server. Createobject ("ADODB. Recordset ")
SQL = "Select * from [Table name]"
Rs. open SQL, conn, 1, 3
While not rs. eof
Rs ("field name") = replace (rs ("field name"), "replaced character", "replaced character ")
Rs. update
Rs. movenext
Wend
Rs. close
Set rs = nothing
Conn. close
Set conn = nothing
%>

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.