ahmedsa2018
Programmer
I work on sql server 2019 i have table #parts have group of numbers on Part Value Field .
my issue how to give unique number to every group of numbers on Part Value Field
if group numbers on part Value not exist before on table then it will take new number.
if group numbers on part Value exist on table it will give same number that exist per group on table
original table as below :
and IF add New Part it will get number 3 as it exist on original table
and IF add New Part it will get number 2 as it exist on original table
and IF add New Part it will get number 4 as new number that consist (max numbers for original table)+ 1
so please how to solve it without using stuff numbers or string aggregate ?
i don't need to use logic below because it will performance issue for big count
may be using string aggregte or stuff as 1,2,3 or 1,2 or 1,2,3,4 and give every group of numbers unqiue number .
to get different between every group
but i don't need to use this logic by stuff or string aggregte
my issue how to give unique number to every group of numbers on Part Value Field
if group numbers on part Value not exist before on table then it will take new number.
if group numbers on part Value exist on table it will give same number that exist per group on table
original table as below :
Code:
create table #parts
(
PartNumber varchar(50),
PartValue int,
UniqueNumber int
)
insert into #parts(PartNumber,PartValue,UniqueNumber,UniqueNumber)
values
('P1',1,1),
('P1',2,1),
('P1',3,1),
('P1',4,1),
('P2',1,2),
('P2',2,2),
('P3',1,3),
('P3',2,3),
('P3',3,3)
Code:
('P4',1,3),
('P4',2,3),
('P4',3,3)
Code:
('P5',1,2),
('P5',2,2)
Code:
('P6',1,4),
('P6',2,4),
('P6',3,4),
('P6',4,4),
('P6',5,4)
i don't need to use logic below because it will performance issue for big count
may be using string aggregte or stuff as 1,2,3 or 1,2 or 1,2,3,4 and give every group of numbers unqiue number .
to get different between every group
but i don't need to use this logic by stuff or string aggregte