Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
SQL

Get the User Name and Domain Name from an Email Address in SQL

- 11.06.18 | 22.11.19 - ErcanOPAK

You can use query below:

DECLARE @Email     VARCHAR(50) = 'info@ercanopak.com'

SELECT SUBSTRING(@Email, 1, CHARINDEX('@', @Email) - 1) AS [User Name],
       SUBSTRING(@Email, CHARINDEX('@', @Email) + 1, LEN(@Email)) AS [Domain Name]

User Name   Domain Name
----------- -------------
info        ercanopak.com

Related posts:

Return number of rows affected by UPDATE statements in SQL

SQL Blocking vs Deadlocks — Most Developers Confuse Them

SQL Index Fragmentation — What Actually Matters (and What Doesn't)

Post Views: 915

Post navigation

Get the First and Last Word from a String or Sentence in SQL
Convert a Comma-Delimited List to a Table in SQL

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

December 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031  
« Nov    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (915)
  • Get the First and Last Word from a String or Sentence in SQL (798)
  • How to select distinct rows in a datatable in C# (772)
  • How to add default value for Entity Framework migrations for DateTime and Bool (772)
  • How to make theater mode the default for Youtube (594)
  • Add Constraint to SQL Table to ensure email contains @ (558)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (534)
  • Average of all values in a column that are not zero in SQL (505)
  • Find numbers with more than two decimal places in SQL (421)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (416)

Recent Posts

  • Visual Studio High CPU When Idle? Live Code Analysis
  • WordPress Slow Admin Panel? Heartbeat API
  • Windows 11 Micro-Stutters in Apps? Disable MPO
  • Windows 11 Laptop Slow on Battery? CPU Throttling
  • AJAX Requests Fail Randomly? CSRF Token Missing
  • JS “await” Inside forEach Is a Bug
  • HTML5 Lazy Loading Without JavaScript
  • CSS 100vh Is Broken on Mobile (Real Fix)
  • ASP.NET Core Thread Pool Starvation Explained
  • ASP.NET Core Logging Slows Your API (Yes, Really)

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (915)
  • Get the First and Last Word from a String or Sentence in SQL (798)
  • How to select distinct rows in a datatable in C# (772)
  • How to add default value for Entity Framework migrations for DateTime and Bool (772)
  • How to make theater mode the default for Youtube (594)

Recent Posts

  • Visual Studio High CPU When Idle? Live Code Analysis
  • WordPress Slow Admin Panel? Heartbeat API
  • Windows 11 Micro-Stutters in Apps? Disable MPO
  • Windows 11 Laptop Slow on Battery? CPU Throttling
  • AJAX Requests Fail Randomly? CSRF Token Missing

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2025 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com