'How can get the first 4 char column 1 that is exact match to column 2 in sql

Question 4 First, create a list of all the contact people where the first 4 characters of their last name are equal to the first 4 characters of their email address. Second find all the contact people whose first name and the last name begin with the same character, create a new column called full name combining their first name and their last name. Finally, add a column with the length of the full name.



Solution 1:[1]

To get the first characters of a string in SQL Server use the built in function:

LEFT(yourColumn, numberOfCharacters)

Example:

LEFT(usrEmail, 4)

To get the length of a string, use the built in function:

LEN(yourString)

Example:

LEN(usrForename + usrSurname)

And to declare a new column just use 'AS' in your select. Example:

SELECT 
usrForename + ' ' + usrSurname AS FullName

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 cking888