If your table has a self-growing column, you can use the following statement to do it once, and you can ensure that the code will not insert duplicate values.
Declare @ namevarchar (4);
-Max (id) is the maximum value of the self-growing column id.
set @ name =(right(' 0000 '+convert(varchar(5),((select max(id)from table)+ 1),4));