In SQL Server, you can use the T-SQL REPLACE()
function to replace all instances of a given string with another string. For example, you can replace all occurrences of a certain word with another word.
Category: SQL
How to Return the Unicode Value for a given Character in SQL Server – UNICODE()
One of the functions included in T-SQL is the UNICODE()
function. You can use this function with SQL Server (and Azure) to return the Unicode value of a given character.
This function works similar to the ASCII()
function, except that it returns the Unicode value.
How to Return the ASCII Code Value for a given Character in SQL Server
If you ever need to find the ASCII code for a given character when using SQL Server, the T-SQL ASCII()
function is probably what you need.
The ASCII()
function returns the ASCII code value of the leftmost character of a character expression. Simply provide the character as an argument and SQL Server will return the ASCII value of that character (or the leftmost character in the string).
SQL Server REPLACE() vs TRANSLATE(): What are the Differences?
Starting with SQL Server 2017, you can now use the T-SQL TRANSLATE()
function to translate one or more characters into another set of characters.
At first glance, you might think that the TRANSLATE()
function does exactly the same thing as the REPLACE()
function, but there are significant differences between the two.
How to Convert Lowercase to Uppercase in SQL Server – UPPER()
In SQL Server, you can convert any lowercase string to uppercase by using the UPPER()
function.
To use it, simply pass the string as an argument when calling the function.
How to Convert Uppercase to Lowercase in SQL Server – LOWER()
In SQL Server, you can convert any uppercase string to lowercase by using the LOWER()
function.
Simply provide the string as an argument when you call the function, and it will be returned in lowercase form.
How to Select a Certain Number of Characters from the Left or Right of a String in SQL Server
If you ever find yourself wanting only the first part of a string, or the last part of it, this article might help.
This article is specific to SQL Server, but the functionality is pretty common across most/all database management systems, not to mention most programming languages.
When working with SQL Server, you can use theT-SQL LEFT()
and RIGHT()
functions to return any given number of characters from the left or right of a string.
How to Return a String in Reverse Order using SQL Server – REVERSE()
Starting from SQL Server 2008, the REVERSE()
function can be used to reverse the order of a string. That is, it returns the characters in the string in reverse order.
Here’s the syntax:
REVERSE ( string_expression )
Where string_expression
is an expression of a string or binary data type. It can be a constant, variable, or column of either character or binary data.
3 Ways to Return a String of Multiple Spaces in SQL Server
When working with databases and the associated data, sometimes you need to insert a space when joining two strings together, or sometimes you need to replace a character with a space.
And then sometimes you need to insert multiple spaces. Here are 3 ways to return a string of multiple spaces in SQL Server using T-SQL.
How to Remove Leading and Trailing Characters in SQL Server
In SQL Server, the TRIM()
function is commonly used to remove leading and trailing whitespace from a string. But did you know that you can also remove other characters from the start/end of a string? It doesn’t have to be whitespace.
TRIM()
is a T-SQL function that specifically removes the space character char(32)
or other specified characters from the start or end of a string.