I have strings in a database like this:
[email protected]/IMCLientName
And I only need the characters that appear before the @ symbol.
I am trying to find a simple way to do this in SQL.
Building on Ian Nelson's example we could add a quick check so we return the initial value if we don't find our index.
DECLARE @email VARCHAR(100)
SET @email = 'firstname.lastname.email.com/IMCLientName'
SELECT CASE WHEN CHARINDEX('@',@email) > 0
THEN SUBSTRING(@email,0, CHARINDEX('@',@email))
ELSE @email
END AS email
This would return 'firstname.lastname.email.com/IMCLientName'. If you used '[email protected]/IMCLientName' then you would receive 'firstname.lastname' as a result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With