Table of Contents

    Real-Time Examples of SQL Functions: Practical Applications and Use Cases

    Real-Time Examples of SQL Functions: Practical Applications and Use Cases

    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))