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

  • SEARCH
  • Home
  • 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 384785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:24:51+00:00 2026-05-12T15:24:51+00:00

I have a table with an Identity column which provides my ticketNumber. I want

  • 0

I have a table with an Identity column which provides my ticketNumber.

I want another table to provide a ticketStepNumber. A ticket may have 0 or more steps, so I won’t always be creating a ticketStepNumber.

The ticketStepNumber value is a combination of the ticketNumber column (int) and the stepNumber column (int). I’d like to define the stepNumber column like an identity but starting at 1 for each value of the ticketNumber column, so all I have to do in my stored procedure is pass in a ticketNumber and I’ll get the new stepNumber. E.g.

ticketNumber  stepNumber
1             1
2             1
2             2
2             3
4             1
7             1
7             2

Is there a way to define this in the table definition or do I have to do it in the SP?

  • 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-12T15:24:52+00:00Added an answer on May 12, 2026 at 3:24 pm

    No, there’s no such thing in SQL Server, sorry. An IDENTITY column is a single, ever-increasing column – there’s no basing that number on the values of another column.

    If you really must have a sequential number for each step, then you’ll have to handle the assignments (and make sure it’s truly unique) yourself.

    UPDATE: if you have some other column in your table that could serve as a sort expression, you could use the ROW_NUMBER function to achieve what you want; e.g. if you had a TicketDate (DATETIME) column, you could do something like:

    SELECT 
       TicketNUmber, 
       ROW_NUMBER() OVER (PARTITION BY TicketNumber ORDER BY TicketDate) AS StepNumber
    FROM YourTable
    

    This would “partition” your data by TicketNumber (e.g. start counting at 1 for each of the values in the partition) and then use the ROW_NUMBER to sequentially number the rows, based on the TicketDate for ordering.

    Marc

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

Sidebar

Related Questions

I have a table which has no identity column. I want to change a
I have a table with one and only one column, which is an identity
I have a table which includes an identity column but i cant remove the
Why transaction does not rollback Identity column. I have a table named DetailReports which
I have a table User which has an identity column UserID , now what
I have a table with an identity column that have incremented by 1 for
So I have a table with an identity column as the primary key, so
OK, I have a table with no natural key, only an integer identity column
I just noticed that if I have an identity column in a table, when
Suppose I have a table, the first column is an identity. I thought that

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.