DECLARE @str VARCHAR( -)SET @str='ap-fqc-2014072300004'--gets the position of the first occurrence of the specified characterSELECT PATINDEX('%-%',@str)--returns: 3--gets the string before the position of the first occurrence of the specified characterSELECT SUBSTRING(@str,1,CHARINDEX('-',@str)-1)--back to: AP--gets the position of the last occurrence of the specified characterSELECT LEN(@str)-CHARINDEX('-',REVERSE(@str))+1 --returns: 7--gets the character between the first occurrence of the specified character and the position of the second occurrenceSELECT SUBSTRING(@str,PATINDEX('%-%',@str)+1,LEN(@str)-CHARINDEX('-',REVERSE(@str))+1-PATINDEX('%-%',@str)-1)--return: FQC--gets all strings after the position where the specified character last appearsSELECT REVERSE(SUBSTRING(REVERSE(@str),1,CHARINDEX('-',REVERSE(@str))-1))--return: 2014072300004