Teja Teja - 7 months ago 26
SQL Question

Select @ before values

I want to select name in email

Example:

sample@gmail.com


From that, I want to select
'sample'
only.

Answer

This is for MS SQL Server. You can easily replicate this if you use any other RDBMS

declare @email varchar(100)
set @email='sample@gmail.com'
select substring(@email,1,charindex('@',@email)-1)