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 8653151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:28:27+00:00 2026-06-12T14:28:27+00:00

I have a situation and I am weak at SQL. Here it is. I

  • 0

I have a situation and I am weak at SQL. Here it is.

I have archived items, that are stored with a number. It is like this in the database table.

RowId   Number  CaseId
234        1       787
235        2       787
236        3       787
237        4       787
238        5       787

This is how it looks when first inserted. But after deleting, take Number 3 is deleted, It is now like this on DB.

RowId   Number  CaseId
234        1       787
235        2       787   
237        4       787
238        5       787

3 is gone but what I need is this.

RowId   Number  CaseId
234        1       787
235        2       787   
237        3       787
238        4       787

The numbers should be updated too. But I can’t figure out a way to do this. By the way, there are many CaseId’s. I won’t update the whole table, I will select it by a CaseId. Can you tell me how to do this? I am using C# .NET

Should I take them in to a list (the way they are ordered from Select query) and check one by one and then update them? I can write the check one by one on C# but I think it won’t be efficient. What is an efficient way to do this?

  • 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-06-12T14:28:28+00:00Added an answer on June 12, 2026 at 2:28 pm

    Does Number have to be updated in the database itself? If not, do you even need to store this? Also are you writing SQL queries? Or just using Entity Framework? If you are writing actual queries, and if you just want the row number when you select the data back you can try something like:

    SELECT RowId, ROW_NUMBER() OVER (ORDER BY RowId ASC) AS [Number], CaseId 
    FROM [MyTable] 
    WHERE CaseID = 787
    

    EDIT: As pointed out by @Mike in the comments, it would probably make sense to make a view out of this. You can remove [Number] from the primary table and make a view like:

    CREATE VIEW dbo.MyView 
    AS 
        SELECT RowId, 
        ROW_NUMBER() OVER (PARTITION BY CaseId ORDER BY RowId ASC) AS Number, 
        CaseId FROM MyTable
    

    The PARTITION statement will make sure that Number resets for every distinct RowId

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

Sidebar

Related Questions

I have situation like this: I have commited files a,b,c,d.Now i found that by
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation like this: user submits form with action='/pay' in '/pay' I have
I just wondered how people were approaching this situation. It's something that seems like
I have situation like this: Range formulaCells = range.SpecialCells(XlCellType.xlCellTypeFormulas); And I want to iterate
I have situation like this: I am doing my own mvc project in visual
I have situation where I generate stylesheets based on information in the database. This
I have situation like this: // Object Class class Person_Object { protected $_id; public
I have this situation where I declare inside my main class a function that
I have situation where in the regular expression is something like this: ^b?A+b?$ So

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.