create table #TempRouting( id int, routetype char(4), routesequence int)
insert into #TempRouting (id,routetype) values (1,'MON')
insert into #TempRouting (id,routetype) values (1,'MON')
insert into #TempRouting (id,routetype) values (2,'MON')
insert into #TempRouting (id,routetype) values (3,'MON')
insert into #TempRouting (id,routetype) values (4,'MON')
insert into #TempRouting (id,routetype) values (5,'MON')
insert into #TempRouting (id,routetype) values (5,'MON')
insert into #TempRouting (id,routetype) values (6,'MON')
DECLARE @id INT
SET @id = 1
IF exists (select id from #temprouting group by id having count(id) > 1)
begin
UPDATE #TempRouting
SET @id = routesequence = @id
END
ELSE
begin
UPDATE #TempRouting
Set @id = routesequence = @id + 1
end
select * from #TempRouting
This is my current result.
id routetype routesequence
1 MON 1
1 MON 1
2 MON 1
3 MON 1
4 MON 1
5 MON 1
5 MON 1
6 MON 1
This is what I want:
id routetype routesequence
1 MON 1
1 MON 1
2 MON 2
3 MON 3
4 MON 4
5 MON 5
5 MON 5
6 MON 6
Any Ideas? Basically if the ID is the same it should not increase the routesequence