title: How to get max value from string value in sql
body: <p>I have a data like this. </p>
  
  <pre><code>1000/PST-FDI/XII/2016
  999/PST-TGR/XII/2016
  998/PST-TGL/XII/2016
  997/PST-SPM/XII/2016
  996/PST-SPG/XII/2016
  995/PST-SMG/XII/2016
  994/PST-SMD/XII/2016
  993/PST-SLT/XII/2016
  </code></pre>
  
  <p>The format value of the serial no is "SequenceNo/BranchCode/Month/Year". I want to select the last sequence no on this year. I made already select top 1 * from table order by serialNo desc, but it show me 999/PST-TGR/XII/2016. I don't know why. </p>
  
  <p>I try to make a function like this</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  ALTER FUNCTION [dbo].[getFirstNumeric](
      @s VARCHAR(50)
  )  
  RETURNS int AS 
  BEGIN
  
  set @s = substring(@s,patindex('%[0-9]%',@s),len(@s)-patindex('%[0-9]%',@s) + 1) 
  if patindex('%[^0-9]%',@s) = 0
      return @s
  set @s = substring(@s,1,patindex('%[^0-9]%',@s)-1) 
  
  return cast(@s as int)
  end
  </code></pre>
  
  <p>also it show for me 999/PST-TGR/XII/2016. Or because I made DESC so it comes late latest word 'PST-TGR' ?? so how to noticed just the sequence no based on the current year ?</p>