Try this. I use something similar for counting the number of commas in a string.
--drop table ast create table ast (field1 varchar(128)) insert into ast select '000' union select '*111' union select '*222*' union select '333***' union select '*4*4*4*' union select '5*5*5***' union select '**66*6***' -- count the number of * before select (LEN(field1) - LEN(REPLACE(field1, '*', ''))) as "*Count", field1 from ast order by 1 -- once you know how to count the number of *, the rest is easy update ast set field1 = field1 + replicate ('*', 5 - (LEN(field1) - LEN(REPLACE(field1, '*', '')))) where (LEN(field1) - LEN(REPLACE(field1, '*', ''))) < 5
-- count the number of * after
select (LEN(field1) - LEN(REPLACE(field1, '*', ''))) as "*Count", field1 from ast order by 1