if you use a table with a max value, be sure to proper locking to prevent race conditions or use a single statement:
create table NextOrderNumber
(
Year int not null,
Number int not null
)
go
declare @year int = 2023;
declare @number int = 1;
merge NextOrderNumber as n
using (select @year as year) as y
on n.Year = y.Year
when matched then
update set
Number = Number + 1,
@number = Number + 1
when not matched then
insert (Year, Number)
values (y.year, @number);
select cast(@year as varchar(4)) + right('0000' + cast(@number as varchar(5)), 4);