clear markdown compare help best fiddles feedback dbanow.uk
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 2591569 fiddles created (45738 in the last week).

create table locations (id int identity primary key, location_id varchar(10));
 hidden batch(es)


insert into locations values ('001'),('001'),('001'),('001'),('001'),('001'),('001'),('001'),('001'),('001'), ('001'), ('002'),('002'),('002'),('002'),('002'),('002'),('002'),('002'), ('003'),('003'),('003'),('003'),('003'),('003'),('003'),('003'),('003'),('003'), ('003'),('003'),('003'),('003'),('003'),('003');
35 rows affected
 hidden batch(es)


SELECT id, location_id, CONCAT (location_id, '-', CAST(ROW_NUMBER() OVER (PARTITION BY location_id ORDER BY id) / 10 as VARCHAR(10)) ) as partition FROM locations
id location_id partition
1 001 001-0
2 001 001-0
3 001 001-0
4 001 001-0
5 001 001-0
6 001 001-0
7 001 001-0
8 001 001-0
9 001 001-0
10 001 001-1
11 001 001-1
12 002 002-0
13 002 002-0
14 002 002-0
15 002 002-0
16 002 002-0
17 002 002-0
18 002 002-0
19 002 002-0
20 003 003-0
21 003 003-0
22 003 003-0
23 003 003-0
24 003 003-0
25 003 003-0
26 003 003-0
27 003 003-0
28 003 003-0
29 003 003-1
30 003 003-1
31 003 003-1
32 003 003-1
33 003 003-1
34 003 003-1
35 003 003-1
 hidden batch(es)