> DECLARE @Tstr TABLE (strvalue varchar(max),Seq int Identity) > INSERT INTO @Tstr (strvalue) VALUES > ('a1-10'),('d5-7'),('abd9-15'),('b-10'), > ('cdf-jhsss'),('dd1-msdhe'),('egh2-xx6'), > ('egh2-egh12'),('ff4-8jj'),('asd122'), > ('U 50'),('For U9'),('1-12') > -- I have tried the following > -- I need to recognize item 1,2 an 3 only, but this code will also return 1 for the items number 7,8 an 9 > select *, PATINDEX('%[a-zA-Z]%[0-9]%-%[0-9]%',strvalue) from @Tstr > > >>Please help
DECLARE @Tstr TABLE (strvalue varchar(max),Seq int Identity) INSERT INTO @Tstr (strvalue) VALUES ('a1-10'),('d5-7'),('abd9-15'),('b-10'), ('cdf-jhsss'),('dd1-msdhe'),('egh2-xx6'), ('egh2-egh12'),('ff4-8jj'),('asd122'), ('U 50'),('For U9'),('1-12') -- I have tried the following -- I need to recognize item 1,2 an 3 only, but this code will also return 1 for the items number 7,8 an 9 select *, PATINDEX('%[a-zA-Z][0-9][-][0-9]%',strvalue) from @TstrBut I don't see a way to express numbers only after dash. We may try using [-][^a-z] but this will exclude letters but doesn't guarantee numbers only.