Your problem might be solved with a variation on the algorithm used in this articleIs this queryselect bugnum=substring(resolution, patindex('%BUG[0-9][0-9][0-9][0-9][0-9][0-9]%', resolution),8) from tickets where resolution like '%BUG[0-9][0-9][0-9][0-9][0-9][0-9]%' and ticket_num in ( select ticket_num from tickets where cust_num = 999999 )doing the same thing as:select bugnum=substring(resolution, patindex('%BUG[0-9][0-9][0-9][0-9][0-9][0-9]%', resolution),8) from ticketswhere resolution like '%BUG[0-9][0-9][0-9][0-9][0-9][0-9]%'and cust_num = 999999