Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: SQL replace function?


Message #1 by "Brad Bansner" <brad@b...> on Mon, 5 Nov 2001 18:24:32
  Brad,
From the "SQL Server Books OnLine" :
******************************************
REPLACE (T-SQL)
Replaces all occurrences of the second given string expression in the first
string expression with a third expression.

Syntax
REPLACE('string_expression1', 'string_expression2', 'string_expression3')

Arguments
'string_expression1' 
Is the string expression to search for string_expression2.
string_expression1 can be of character or binary data. 
'string_expression2' 
Is the string expression for which to search in string_expression1 and to
replace with string_expression3. string_expression2 can be of character or
binary data. 
'string_expression3' 
Is the new string expression that replaces string_expression2 in
string_expression1. string_expression3 can be of character or binary data. 
Return Types
Returns character data if string_expression (1, 2, or 3) is one of the
supported character data types. Returns binary data if string_expression (1,
2, or 3) is one of the supported binary data types. 

Examples
This example replaces the string cde in abcdefghi with xxx.

SELECT REPLACE('abcdefghicde','cde','xxx')

GO

  

Here is the result set:

------------------------------------------------------------------------

abxxxfghixxx

(1 row(s) affected)

*************************************************************************

	Good luck!
	Eva

-----Original Message-----
From: Brad Bansner [mailto:brad@b...]
Sent: Monday, November 05, 2001 4:07 PM
To: sql language
Subject: [sql_language] RE: SQL replace function?


I'm using Microsoft SQL Server 7.0. I can't find anything in my DOC's about
a REPLACE function.

Thanks,
-Brad



> From: Kyle Burns <kburns@c...>
> Reply-To: "sql language" <sql_language@p...>
> Date: Mon, 5 Nov 2001 15:21:14 -0500
> To: "sql language" <sql_language@p...>
> Subject: [sql_language] RE: SQL replace function?
> 
> What DBMS are you using? T-SQL for SQL Server has the REPLACE function.
> 
> 
> =================================
> Kyle M. Burns, MCSD, MCT
> ECommerce Technology Manager
> Centra Credit Union
> kburns@c...
> 
> 
> 
> 
> -----Original Message-----
> From: Brad Bansner [mailto:brad@b...]
> Sent: Monday, November 05, 2001 1:25 PM
> To: sql language
> Subject: [sql_language] SQL replace function?
> 
> 
> Is it possible to do a replace function in a SQL select statement which is
> similar to 
> what I would accomplish in VB like this:
> 
> given that field1 = "fname \lname"
> 
> VB to remove the backslash would be: replace(field1, "\","")
> 
> ...so that I can search it in SQL? Similar to this...
> 
> select * from tbl_data where replace(field1,"\","")="fname lname"
> 
> I have a client who has these backslashes in the field data for other
> purposes, yet I 
> need to make them searchable without the backslashes.
> 
> Thank you,
> -Brad
> 
$subst('Email.Unsub')
> 
> 
$subst('Email.Unsub')
> 




  Return to Index