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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:46:25+00:00 2026-05-20T05:46:25+00:00

given this table and data: DECLARE @Table table (RowID int, RowCode char(1), RowValue int);set

  • 0

given this table and data:

DECLARE @Table table (RowID int, RowCode char(1), RowValue int);set nocount on
INSERT @Table VALUES ( 6,'A',3757 )
INSERT @Table VALUES ( 5,'A',37827)
INSERT @Table VALUES (14,'A',48411)
INSERT @Table VALUES ( 1,'A',48386)
INSERT @Table VALUES (20,'A',48450)
INSERT @Table VALUES ( 7,'A',46155)
INSERT @Table VALUES (13,'A',721  )
INSERT @Table VALUES ( 2,'A',49335)
INSERT @Table VALUES (15,'A',4700 )
INSERT @Table VALUES (19,'A',64416)
INSERT @Table VALUES ( 8,'A',27246)
INSERT @Table VALUES (12,'B',54929)
INSERT @Table VALUES (16,'B',3872 )
INSERT @Table VALUES ( 3,'C',728  )
INSERT @Table VALUES (11,'C',1050 )
INSERT @Table VALUES ( 9,'C',3191 )
INSERT @Table VALUES (17,'C',866  )
INSERT @Table VALUES ( 4,'C',838  )
INSERT @Table VALUES (10,'D',550  )
INSERT @Table VALUES (18,'D',1434 );set nocount off

I need this:

                       VVVVVVVV
RowID RowCode RowValue RowChunk
----- ------- -------- --------
1     A       48386    1       
2     A       49335    1       
5     A       37827    1       
6     A       3757     1       
7     A       46155    1       
8     A       27246    2       
13    A       721      2       
14    A       48411    2       
15    A       4700     2       
19    A       64416    2       
20    A       48450    3       
12    B       54929    4       
16    B       3872     4       
3     C       728      5       
4     C       838      5       
9     C       3191     5       
11    C       1050     5       
17    C       866      5       
10    D       550      6       
18    D       1434     6    

RowChunk starts at 1 and is incremented by 1 for each RowCode change and/or when there have been 5 of the same RowCode values.

  • 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-20T05:46:26+00:00Added an answer on May 20, 2026 at 5:46 am

    Basically my solution uses the same approach as yours, only with slightly different devices employed.

    WITH NumberedRows AS (
      SELECT
        RowID,
        RowCode,
        RowValue,
        CodeChunk = (ROW_NUMBER() OVER (PARTITION BY RowCode ORDER BY RowID) - 1) / 5
      FROM @Table
    )
    SELECT
      RowID,
      RowCode,
      RowValue,
      RowChunk = DENSE_RANK() OVER (ORDER BY RowCode, CodeChunk)
    FROM NumberedRows
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the example queries below (Simplified examples only) DECLARE @DT int; SET @DT=20110717; --
Some sample data: DECLARE @TARGET TABLE ( ID INT, value INT ) ; DECLARE
Given this: create table Location( LocationId int identity(1,1) not null primary key, Address nvarchar(max)
given this coffeescript data = Foo: B Foos: [ A, B ] Blah: Id:
Is there a proper term in data modeling to describe the following? Given table
I have my table schema and data something like this CompanyCategoryId SubCategoryId CategoryId CompanyId
Given a table (TableA) that contains the following data; Id Date Status RecordId 1
I have a data set consisting of time-stamped values, and absolute (meter) values. Sometimes
I am displaying a scrolled data table in a web page. This table has
when i give this sql query in my msaccess database table called warehouse1 it

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.