sql - Numberpart of a string in specific range -
i'm using sqlserve , need rows part of string within specific numberrange.
as illustration i've got in column uniquestringid:
be09 mytest be10 mytest ce101 mytest ce300 mytestand want rows number within uniquestringid (the number has located before space) between (including) 10 , 101
so result be:
be10 mytest ce101 mytestmy question here possible sql or need stored procedure that? , if former how sql be?
drop table #t create table #t(id varchar(100)) insert #t values('be09 mytest'), ('be10 mytest'), ('ce101 mytest'), ('ce300 mytest'), ('ce450595 mytest') select id,cast(substring(id,patindex('%[0-9]%',id),patindex('%[a-z0-9] [a-z]%',id)-1) int) #t cast(substring(id,patindex('%[0-9]%',id),patindex('%[a-z0-9] [a-z]%',id)-1) int) between 10 , 101
fiddle demo
fiddle demo few more test cases
sql sql-server
No comments:
Post a Comment