Real time example SQL Function

Rumman Ansari   Software Engineer   2023-03-25   5602 Share
☰ Table of Contents

Table of Content:


Real time example, where we can use LEN(), CHARINDEX() and SUBSTRING() functions. Let us assume we have table as shown below.

Real time example SQL Function

Write a query to find out total number of emails, by domain. The result of the query should be as shown below.

Code:


Select SUBSTRING(Email, CHARINDEX('@', Email) + 1,
LEN(Email) - CHARINDEX('@', Email)) as EmailDomain,
COUNT(Email) as Total
from TableEmployee
Group By SUBSTRING(Email, CHARINDEX('@', Email) + 1,
LEN(Email) - CHARINDEX('@', Email))