Saturday, December 27, 2014

Difference beteween stuff and replace function in sql server

STUFF function is used to overwrite existing characters. Here is the syntax of stuff function
stuff (Expression, start, length, replace),
Expression is the string that will have characters substituted
start is the starting position
length is the number of characters in the string that are substituted
replace are the new characters interjected into the string
Here is the   example of stuff function
SELECT STUFF('anil kumar', 1, 2, 'sun');
Output this query = sunil kumar

REPLACE function to replace existing characters of all occurrences.
Using the syntax REPLACE (string_expression, search_string, replacement_string), where every incidence of search_string found in the string_expression will be replaced with replacement_string.
Here  is the example
select REPLACE('Sunil Kumar asp.net devloper','Sunil','Anil' )

output of this query is: Anil Kumar asp.net devloper

No comments:

Post a Comment

http://blogsiteslist.com