sql - How to generate 5 digit increment number based on Zone? -
out put : if north "n00001 n00002 if south "s00001 s00002 here tried code declare @zone varchar(20),@zoneid int,@id varchar(10) set @zone = 's' select @zoneid = cast(isnull(max(cast(replace(idno,@zone,'') numeric))+1,'00000') varchar) memberprofiles left(idno,1) = @zone set @id = @zone+cast(@zoneid varchar) select @id but every time getting "s1" need "s00001" how can generate zone wise number generation this question "closed duplicate" candidate. but, there several flaws, think it's worth answer: in database seem have column "idno" leading character marking zone. if true, should - if ever possible - change design. number , zone mark should reside in 2 columns. combination of them presentation issue your left(idno,1) perform badly (read "sargability"). if there...