10

I have this type of values in table column

154646@8@486
45465@6464@654

etc.

How can i remove everything after second @ character ? I need to display

154646@8
45465@6464

I can do it only for all @ but not for second

SELECT REPLACE(LEFT('45@Tra@lala', CHARINDEX('@','45@Tra@lala')-1),'_',' ')

returns 45 but not 45@Tra

Thank you :-)

asked Jan 16, 2015 at 13:13
0

1 Answer 1

16

You can use the third parameter of charindex() that is used to specify where in the string the search will start.

declare @S varchar(20) = '45465@6464@654';
select left(@S, charindex('@', @S, charindex('@', @S)+1)-1);

Result

45465@6464
answered Jan 16, 2015 at 13:17
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.