Tag sql server management studio

SQL LEN Function

Example Return the length of a string: SELECT LEN(‘Iampsp.com’); Definition and Usage The LEN() function returns the length of a string. Note: Trailing spaces at the end of the string is not included when calculating the length. However, leading spaces…

SQL LEFT Function

Example Extract 3 characters from a string (starting from left): SELECT LEFT(‘SQL Tutorial’, 3) AS ExtractString; Definition and Usage The LEFT() function extracts a number of characters from a string (starting from left). Syntax LEFT(string, number_of_chars)

SQL FORMAT Function

Example Format a date: DECLARE @d DATETIME = ’12/01/2018′; SELECT FORMAT (@d, ‘d’, ‘en-US’) AS ‘US English Result’,                FORMAT (@d, ‘d’, ‘no’) AS ‘Norwegian Result’,                FORMAT (@d, ‘d’, ‘zu’) AS ‘Zulu Result’; Definition and Usage The FORMAT() function…

SQL Server DIFFERENCE Function

Example Compares two SOUNDEX values, and return an integer: SELECT DIFFERENCE(‘Juice’, ‘Jucy’); Definition and Usage The DIFFERENCE() function compares two SOUNDEX values, and returns an integer. The integer value indicates the match for the two SOUNDEX values, from 0 to…

SQL Server DATALENGTH Function

Example Return the length of an expression (in bytes): SELECT DATALENGTH(‘W3Schools.com’); Definition and Usage The DATALENGTH() function returns the number of bytes used to represent an expression. Note: The DATALENGTH() function counts both leading and trailing spaces when calculating the…

SQL Server CONCAT_WS Function

Example Add strings together. Use ‘.’ to separate the concatenated string values: SELECT CONCAT_WS(‘.’, ‘www’, ‘iampsp’, ‘com’); Definition and Usage The CONCAT_WS() function adds two or more strings together with a separator.   Syntax CONCAT_WS(separator, string1, string2, …., string_n)

SQL Server Concat With +

Example Add 2 strings together: SELECT ‘iampsp’ + ‘.com’; Definition and Usage The + operator allows you to add two or more strings together.   Syntax string1 + string2 + string_n

SQL Server CONCAT Function

Example Add two strings together: SELECT CONCAT(‘iampsp’, ‘.com’); Definition and Usage The CONCAT() function adds two or more strings together.   Syntax CONCAT(string1, string2, …., string_n)

SQL Server CHARINDEX Function

Example Search for “t” in string “Customer”, and return position: SELECT CHARINDEX(‘t’, ‘Customer’) AS MatchPosition; Definition and Usage The CHARINDEX() function searches for a substring in a string, and returns the position. If the substring is not found, this function…