I think you're looking for CHARINDEX()
in conjunction with SUBSTRING()
. With that, you can split off that _# to another variable like this (copy/pasta and execute to see. Play with the @temp1 variable to see the limitations of the code):
declare @temp1 varchar(20), @temp2 varchar(20)
set @temp1 = '1234567891123_12'
IF CHARINDEX('_', @temp1) > 1
set @temp2 = SUBSTRING(@temp1,CHARINDEX('_', @temp1),LEN(@temp1)-CHARINDEX('_',@temp1)+1)
select @temp1, @temp2
Hope it helps!