dev-exchange.com logo

dev-exchange.com latest topics RSS feed

Book mark: Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to your delicious account Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to your digg account Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to your blinklist account Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to your reddit account Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to Dzone Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to your furl account Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to your stumble account Add http://www.dev-exchange.com/cms_view_article.php?aid=35&start=0&sid=14043ba0fa3c0d8353b6446ad2e765cb to your Yahoo myweb account
Article Menu
Google
ColdFusion MX
PHP
ASP
ASP.Net
XML-XSLT
JavaScript
SQL Server
AJAX
Android
 


 
Article
MsN
Tech Author

Articles: 7 Comments: 1
 Posted: Wed Jul 09, 2008 12:56 pm

There are quite few useful functions in SQL server to manipulate strings. In this article, we take a look at two functions which can be used for replacing a string within a string.

1. STUFF()

This function can be used for delete a certain length of the string and insert a new string in the deleted place.

Syntax

Code:
STUFF ( InputString, start, length, ReplacedString )


Example

Code:

Select STUFF ("this is a test", 7, 2, "was")
-- Result - this was a test


2. REPLACE()

This function replaces all the occurrences of a string expression with a new string within an input string.

Syntax:

Code:
REPLACE ( InputString , StringToReplace , NewString )


Example,


Code:
Select REPLACE ("This is a test and it is successful!”,"is","was")

-- Result - This was a test and it was successful!



I frequently use REPLACE function but never come across a scenario inserting a specific portion of text in a string after deleting the portion of it. The thing about STUFF() is we need to know the starting position where it needs to insert. Probably we may need to use the functions like CHARINDEX() to find the position of the string before we can insert a new string.


Thanks
Rating: 0.00/5.00 [0]

Comments
No comments were made for this article
 

All times are GMT

Jump to:  
You cannot post articles in this chapter
You cannot edit your articles in this chapter
You cannot delete your articles in this chapter
You cannot rate articles in this chapter

You cannot post comments in this chapter
You cannot edit your comments in this chapter
You cannot delete your comments in this chapter
You cannot rate comments in this chapter


© 2008 dev-exchange.com
Powered by phpBB. Theme DEVPPL.