RSS

How to insert string into another … STUFF() !!

24 Oct

What will you do if you want to merge two strings with each of them … in other words what will you do if you want to insert a string expression into another one using MS SQL Server ??

The STUFF function is the answer … !!

The STUFF function according to MSDN inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

You can see the following example:

— General syntax:  STUFF ( string, start, length, string )

PRINT STUFF(‘Ahmed’,2,3,’Negm’);

— You will see a new string: ANegmd as a result of this built-in function.

 

 


Notice please:

If the start position or the length is negative, or if the starting position is larger than length of the first string, a null string is returned. If the length to delete is longer than the first string, it is deleted to the first character in the first string.

An error is raised if the resulting value is larger than the maximum supported by the return type.

 
Leave a comment

Posted by on October 24, 2011 in MS SQL Server

 

Tags: , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: