If you just want to facilitate communication and cannot use the Identifier column, these are several ways to avoid +1 ;
declare @T TABLE (idx int identity(1, 1), f1 varchar(128), f2 varchar(128)) insert into @T values ('someVal', 'someOtherVal'), ('someVal1', 'someOtherVal3'), ('someVal2', 'someOtherVal4') insert [Bookings].[dbo].[Range] select @startIdx + idx, f1, f2 from @T
Or (identifiers are assigned in alphabetical order out of order based on the 1st field)
insert [Bookings].[dbo].[Range] select @startIdx + row_number() over(order by name1) as n, * from ( select top 0 '' as name1, '' as name2 --header union all select 'someVal', 'someOtherVal' union all select 'someVal1', 'someOtherVal3' union all select 'someVal2', 'someOtherVal4' ) T
Are you sure you want nolock ?
source share