STUFF and REPLACE.

STUFF (character expression, start, length, character expression)

Eg: SELECT STUFF('ABCDEF', 2, 3, 'JKLMN')

ResultSet
AJKLMNEF

What this STUFF Function will do is
1)Checks First two characters in the Character Expression(‘ABCDEF’)
2)Those two characters are BC in the Character Expression.
3)This starts count from B to D (Total Count 3)
4)So it removes BCD and Place JKLMN in that place.
5)So result set appears as AJKLMNEF


REPLACE:
REPLACE will also do the same with the Different way.

REPLACE (string_expression1, string_expression2, string_expression3)
Eg: SELECT REPLACE('ABCDEF','BCD','JKLMN')
ResultSet:
AJKLMNEF

The way REPLACE Works is:
1)First it checks for the BCD in ABCDEF
2)And Remove BCD and Place JKLMN in the place of BCD
3)So output look like as AJKLMNEF

Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server