TGViewer
SQL Programming Resources SQL Programming Resources @sqlanalyst ยท 76.7K subscribers
Post #2482 3.11K
๐Ÿ”ฅNow, letโ€™s move to the next topic:

โœ… SQL String Functions

๐Ÿง  1. What are String Functions?
String functions are used to
๐Ÿ‘‰ manipulate text data
๐Ÿ‘‰ clean messy data
๐Ÿ‘‰ format outputs

Used heavily in:
โœ” Data Analytics
โœ” Reporting
โœ” ETL processes

โšก 2. Common String Functions
Function : Purpose
UPPER() : Convert to uppercase
LOWER() : Convert to lowercase
LENGTH() : Count characters
CONCAT() : Join strings
SUBSTRING() : Extract part of string
TRIM() : Remove spaces
REPLACE() : Replace text

๐Ÿ”ฅ 3. UPPER() & LOWER()

SELECT UPPER(name) AS upper_name
FROM employees;

SELECT LOWER(name) AS lower_name
FROM employees;

๐Ÿ”ฅ 4. LENGTH()
๐Ÿ‘‰ Count number of characters

SELECT name, LENGTH(name) AS total_chars
FROM employees;

๐Ÿ”ฅ 5. CONCAT()
๐Ÿ‘‰ Combine strings

SELECT CONCAT(first_name, ' ', last_name) AS full_name
FROM employees;

๐Ÿ”ฅ 6. SUBSTRING()
๐Ÿ‘‰ Extract part of string
SELECT SUBSTRING(name, 1, 3)
FROM employees;

โœ” Extracts first 3 characters

๐Ÿ”ฅ 7. TRIM()
๐Ÿ‘‰ Remove extra spaces
SELECT TRIM(' SQL ');

โœ” Result โ†’ SQL

๐Ÿ”ฅ 8. REPLACE()
๐Ÿ‘‰ Replace text inside string

SELECT REPLACE('I love Java', 'Java', 'SQL');

โœ” Result โ†’ I love SQL

๐ŸŽฏ 9. Practice Tasks
1. Convert names to uppercase
2. Convert emails to lowercase
3. Combine first & last names
4. Extract first 4 letters of names
5. Remove extra spaces from city names

โšก Mini Challenge ๐Ÿ”ฅ
๐Ÿ‘‰ Create employee usernames using:
first 3 letters of name + employee ID

Example:
Amit + 101 โ†’ Ami101

๐Ÿ”ฅ Mini Challenge Solution ๐Ÿ’ฏ

๐Ÿ‘‰ Requirement:
Create username using:
โ€ข First 3 letters of name
โ€ข Employee ID

Example:
Amit + 101 โ†’ Ami101

โœ… SQL Solution
SELECT name,
emp_id,
CONCAT(SUBSTRING(name, 1, 3), emp_id) AS username
FROM employees;

โœ… Example Output
name : emp_id : username
Amit : 101 : Ami101
Neha : 102 : Neh102
Ravi : 103 : Rav103

๐Ÿง  How It Works
๐Ÿ‘‰ SUBSTRING(name, 1, 3)
Extracts first 3 letters

๐Ÿ‘‰ CONCAT()
Combines extracted text with employee ID

๐Ÿ”ฅ Real-World Usage:
String functions are commonly used for:
๐Ÿ‘‰ Username generation
๐Ÿ‘‰ Email formatting
๐Ÿ‘‰ Data cleaning
๐Ÿ‘‰ Customer IDs ๐Ÿ’ฏ

Double Tap โค๏ธ For More
  • โค 8
  • ๐ŸŽ‰ 1
More from @sqlanalyst
  1. Oct 9, 2026SQL Interview Series โ€” Part 5 ๐Ÿ“Œ Question 5: Find Employees Who Earn More Than Their Managโ€ฆ
  2. Oct 9, 2026๐Ÿ‡ฎ๐Ÿ‡ณ ๐—š๐—ข๐—ฉ๐—˜๐—ฅ๐—ก๐— ๐—˜๐—ก๐—ง ๐—ข๐—™ ๐—œ๐—ก๐——๐—œ๐—” โ€” ๐—”๐—œ๐—–๐—ง๐—˜ ๐—œ๐—ก๐—ง๐—˜๐—ฅ๐—ก๐—ฆ๐—›๐—œ๐—ฃ๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ ๐Ÿš€โ€ฆ
  3. Oct 8, 2026๐ŸŽ“ ๐— ๐—ถ๐—ฐ๐—ฟ๐—ผ๐˜€๐—ผ๐—ณ๐˜ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ฒ๐˜€! ๐Ÿš€๐Ÿ”ฅ Upgrโ€ฆ
  4. Oct 7, 2026๐Ÿš€๐—ฃ๐—ฎ๐˜† ๐—”๐—ณ๐˜๐—ฒ๐—ฟ ๐—ฃ๐—น๐—ฎ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด | ๐—•๐—ฒ๐—ฐ๐—ผ๐—บ๐—ฒ ๐—ฎ ๐—™๐˜‚๐—น๐—น๐˜€๐˜๐—ฎ๐—ฐโ€ฆ
  5. Oct 7, 2026SQL Interview Series โ€” Part 4 ๐Ÿ“Œ Question 4: Find the Highest Salary in Each Department Suโ€ฆ
  6. Oct 7, 2026๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—•๐—œ ๐—ณ๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ”ฅ Learn Power BI through these FREE learninโ€ฆ
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook โ†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 โ†’