I need to find a way to get the numbers between the dashes. This is the only way I know to do it, but I know that not all of our accounts are the same length. So I am just looking for a way to get everything between before, after and between the dashes. This is an example of the types of accounts we have. '2-0-200-325-0' and '1-0-1105-1500-1520' The non-digit characters are only dashes and nothing else.
declare @Department Int
declare @Account Int
declare @Company Int
declare @Location Int
declare @SubAccount Int
declare @AccountNo varchar(24) = '2-0-200-325-0'
declare @CommaPos Int
select @CommaPos = charindex('-',@accountno)
set @Company = substring(@accountno,1,@CommaPos-1)
select @Company as Company
set @Location = Substring(@AccountNo, @CommaPos+1, 1)
select @Location as Location
set @Department = Substring(@AccountNo, @CommaPos+3, 4)
select @Department as Department
set @Account = Substring(@AccountNo, @CommaPos+8, 4)
select @Account as Account
set @SubAccount = Substring(@AccountNo, @CommaPos+13, 4)
select @SubAccount as SubAccount