Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6001359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:49:24+00:00 2026-05-23T00:49:24+00:00

Is there a way to do the following: DECLARE @startVal integer SELECT @startIdx =

  • 0

Is there a way to do the following:

DECLARE @startVal integer

SELECT 
    @startIdx = MAX(Range_val) 
FROM 
    [Bookings].[dbo].[Range] (nolock)

INSERT INTO
    [Bookings].[dbo].[Range]
VALUES
    (INCR(@startVal), 'someVal', 'someOtherVal'),
     (INCR(@startVal), 'someVal1', 'someOtherVal3'),
     (INCR(@startVal), 'someVal2', 'someOtherVal4'),

Where INCR() is some function that increments the variable. Instead of doing ‘@startIdx + 1’, ‘@startIdx + 2’, etc?

EDIT: This is not necessarily the table index. I know I can drop the table and recreate it the proper way (assuming this is the index), but that’s not my question. Is there a way to increment a variable the way I have described?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:49:25+00:00Added an answer on May 23, 2026 at 12:49 am

    If your just looking to make it easier to mess around with & cannot use an
    identity column here are a couple of ways to avoid specifying +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 (ids are assigned in an alphabetical not ordinal 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?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way to do the following in HQL: SELECT case when flag
Is there a way to use a variable in the following manner? DECLARE @ID
Is there a better way than the following to check to see if a
Is there a way to tidy-up the following code, rather than a series of
Is there a way to do the following using LINQ? foreach (var c in
Is there a way to bypass the following IE popup box: The webapge you
Is there any way to retrieve the following type of path: \\?\Volume{GUID}\ for USB
Is there a way to do the following preprocessor directives in Python? #if DEBUG
Is there a way to do the following? I see that the Attribute Arguments
Is there a way to get the following function declaration? public bool Foo<T>() where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.