String Functions in SQL server

SQL provides a variety of string functions that can be used to manipulate and format string values. Here are some examples of commonly used string functions in SQL:

  • CONCAT: This function is used to concatenate two or more strings into a single string. For example, SELECT CONCAT (\’Hello\’, \’World\’) returns the string “HelloWorld”.
  • SUBSTRING: This function is used to extract a substring from a string. For example, SELECT SUBSTRING (\’HelloWorld\’, 1, 5) returns the string “Hello”.
  • LEN: This function is used to return the length of a string. For example, SELECT LEN(\’HelloWorld\’) returns the value 10.
  • UPPER: This function is used to convert a string to uppercase. For example, SELECT UPPER(\’HelloWorld\’) returns the string “HELLOWORLD”.
  • LOWER: This function is used to convert a string to lowercase. For example, SELECT LOWER(\’Hello World\’) returns the string “hello world”.
  • REPLACE: This function is used to replace a substring in a string with another substring. For example, SELECT REPLACE (\’HelloWorld\’, \’World\’, \’Universe\’) returns the string “Hello Universe”.
  • LTRIM: This function is used to remove leading spaces from a string. For example, SELECT LTRIM (\’ HelloWorld\’) returns the string “HelloWorld”.
  • RTRIM: This function is used to remove trailing spaces from a string. For example, SELECT RTRIM (\’HelloWorld \’) returns the string “HelloWorld”.
  • LEFT: This function is used to return a specified number of characters from the beginning of a string. For example, SELECT LEFT (\’HelloWorld\’, 5) returns the string “Hello”.
  • RIGHT: This function is used to return a specified number of characters from the end of a string. For example, SELECT RIGHT (\’HelloWorld\’, 5) returns the string “World”.