The LEFT function returns a specified number of characters from the beginning or left side of a string.
LEFT provides a simple way to extract prefixes, codes, and identifiers from text values.
Extract the first two characters of a branch code.
SELECT
BranchCode,
LEFT(BranchCode, 2) AS RegionCode
FROM Branches;
LEFT is useful for region codes, product prefixes, customer identifiers, and data classification.
- LEFT extracts characters from the beginning.
- The number of characters is specified.
- It is useful for prefixes.
- It simplifies common substring operations.
- Function support varies by database.
What does LEFT do?
LEFT returns a specified number of characters from the beginning of a string.
When would you use LEFT?
LEFT is useful when you need to extract prefixes or leading characters from a text value.