Sqlserver replace Function

Source: Internet
Author: User

Syntax
Replace ('string _ expression1', 'string _ expression2', 'string _ expression3 ')
Parameter description
'String _ expression1'
String expression to be searched. String_expression1 can be character or binary data.
'String _ expression2'
String expression to be searched. String_expression2 can be character or binary data.
'String _ expression3'
String expression used for replacement. String_expression3 can be character 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 this function is called in ASP, an error is prompted: The 'replace 'function in the expression is not defined. You can write a function in ASP to implement this function.
example function: copy Code the code is as follows: function Replace (title)
{< br> Replace (title, 'aaa', 'bbbbb')
return (title)
}< br> BBB = Replace (title)
Update ..... set Title = '"& BBB &"'

reference code for replacing specified characters in ASP + Access in batches: copy Code the 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
%>

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.