String Functions – STUFF()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the STUFF() function today. The STUFF() function takes a source string [S], a starting position [P], a total length [L] and a replacement string [R] as input parameters. It removes [L] characters from the source string [S] starting at position [P] and replaces those changes with string [R]. From the definition of this function, one could easily write a custom user defined function with the same functionality using the…

String Functions – STR()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the STR() function today. The STR() function takes a floating point number [F] to be converted to a string, a integer number [L] representing the total length, and a integer number [D] representing the number of decimal digits as input. It returns a formatted string representing the floating point number. The length [L] includes decimal point, sign, numbers and spaces. The decimal digits [D] represents the number of digits…

String Functions – SPACE()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the SPACE() function today. The SPACE() function takes a positive integer replication count [C] as input. The function returns a string composed of a single space concatenated [C] times to itself as output. The example below adds one, two, and three spaces inside the title of a favorite movie of mine.

One thing to always worry about when using TSQL functions is how will it react with…

String Functions – SOUNDEX()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the SOUNDEX() function today. The SOUNDEX() function calculates a four-character code that is based on how the string sounds when spoken. Please see my prior blog entry for a sample use of this function in conjunction with the DIFFERENCE() function. Soundex was developed by Robert C. Russell and Margaret K. Odell and patented in 1918 / 1922. The United States government created a variation named the American Soundex which…

String Functions – RTRIM()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the RTRIM() function today. The RTRIM() function takes a source string as input and returns a output string with all trailing spaces removed. The following example removes trailing spaces from a favorite movie title of mine.

One thing to always worry about when using TSQL functions is how will it react with empty strings or NULL values? Both empty strings and NULL values as input return themselves…

String Functions – RIGHT()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the RIGHT() function today. The RIGHT() function takes the source string [S] and number of characters [X] as input and returns the [X] rightmost characters from string [S] as output. The following example grabs the last word from a favorite movie title of mine.

One thing to always worry about when using TSQL functions is how will it react with empty strings, NULL values, or invalid values?…

String Functions – REVERSE()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the REVERSE() function today. The REVERSE() function takes a source string as input and returns each character in the reverse order as output. Therefore, the last character input string is now the first character in the output string. And the first character in the input string is last character in the output string. Let’s have some fun by using palidromes in the next example. The example below has two…

String Functions – REPLICATE()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the REPLICATE() function today. The REPLICATE() function takes a pattern string [S] and a integer replication count [C] as input. The function returns a string composed of pattern string [S] concatenated [C] times to itself as output. The example below replicates a pattern ‘XO’ five times.

One thing to always worry about when using TSQL functions is how will it react with a EMPTY strings or NULL…

String Functions – REPLACE()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the REPLACE() function today. The REPLACE() function takes a source string, a search string and a replacement string as input. For each occurrence of the search string found in the source string, change the value to the replacement string. Again, I will be using my favorite movie title in this example. Who does not like the “Wizard of OZ?”. The example below replaces the word “of” with the word…

String Functions – QUOTENAME()

I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the QUOTENAME() function today. The QUOTENAME() function takes a input of type sysname, nvarchar(128) and returns a string, nvarchar(258) with quote characters at front and end of the string. A optional string can be specified to redefine the default quote character for TSQL. The following example creates a table name in the adventure works database from two variables.

The default quote characters [] can be changed by…