Select lpad(Row_number() over(Partition By t.ffcode Order By t.frmaster),2,'0') newid,t.* From tjfpersoninfo t Where t.frcode='230124'