left(substring(docid,charindex('~',docid)+1,len(docid)),7)
declare @vt_t table (docid varchar(50))insert into @vt_tselect '99~B007340~9822151~LR5~250' union allselect '99~B007599~9417974~LC0~240'select substring(docid,charindex('~',docid)+1,7)FirstString, substring(docid,CharIndex('~', docid, charindex('~',docid)+1 + 1) + 1, 7) SecondStringfrom @vt_t-- Use this if the format for all records are the sameselect substring(docid, 4, 7) FirstString, substring(docid, 12,7) SecondStringfrom @vt_t