Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

How do i re-calculate Index in a table?

$
0
0
-- Template data:
declare @A table (Id int, [Name] nvarchar(256), [Index] int, ProjectId int)

insert into @A values (1, 'D', 1000, 111)
insert into @A values (2, 'C', 5000, 222)
insert into @A values (3, 'B', 7000, 111)
insert into @A values (4, 'A123', 9000, 222)
insert into @A values (5, 'A', 11000, 111)

-- How do i update that table with values:
-- with Index start\increase by 1000
-- Where ProjectId = 111 & OrderBy Name ASC
-- Id    |    Name    |    Index    |    ProjectId    |
-- 1        D            3000        111
-- 3        B            2000        111
-- 5        A            1000        111
-- Where ProjectId = 222 & OrderBy Name ASC
-- Id    |    Name    |    Index    |    ProjectId    |
-- 2        C            2000        222
-- 4        A123        1000        222

Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>