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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:57:16+00:00 2026-05-21T03:57:16+00:00

Below is my table Schema: CREATE TABLE [dbo].[Sample]( [BoardId] [int] IDENTITY(1,1) NOT NULL, [UserCode]

  • 0

Below is my table Schema:

CREATE TABLE [dbo].[Sample](
    [BoardId] [int] IDENTITY(1,1) NOT NULL,
    [UserCode] [nvarchar](20) NOT NULL,
    [Desc] [nvarchar](100) NOT NULL,
    [Version] [int] NOT NULL,
    [ParentId] [int] NULL,
    [CreatedOn] [datetime] NOT NULL,
    [ModifiedOn] [datetime] NOT NULL)

short description about the table, User can opt to save “Desc”[User info as per the user] as a seperate version each time. I would like to generate a version number for each subVersion being created. The parentId field holds the PK ID for which the subversion is being created.
For example, some records below.

boardID        UserCode     Desc       Version   ParentID  CreatedOn       ModifiedOn
1              12343jhgs    blah blah    1          0        ---            ---
2              12343jhgs    blah blah    1          1        ---            ---
3              12343jhgs    blah blah    2          1        ---            ---
4              73627ggjh    lol lol ol   1          0        ---            ---

Hope you are getting the idea, for each subversion created i would like to generate a Version number that increments.

  • 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-21T03:57:17+00:00Added an answer on May 21, 2026 at 3:57 am

    An example based on your sample data. I have assumed that the version number of instances of boardId with the same ParentId is determined by order of insertion.

    EDIT – re-reading your description and comments I realised that the parent and first child having version 1 was intentional:

    DECLARE @Sample TABLE 
    (
        [BoardId] [INT] NOT NULL,
        [UserCode] [NVARCHAR](20) NOT NULL,
        [Desc] [NVARCHAR](100) NOT NULL,
        [ParentId] [INT] NULL,
        [CreatedOn] [DATETIME] ,
        [ModifiedOn] [DATETIME]
    )
    
    INSERT @Sample
    (boardID,UserCode,[Desc],ParentID)
    VALUES
    (1,'12343jhgs','blah blah',0),
    (2,'12343jhgs','blah blah',1),
    (3,'12343jhgs','blah blah',1),
    (4,'73627ggjh','lol lol ol',0)
    
    
    ;WITH recCTE
    AS
    (
        SELECT  boardID,UserCode,[Desc],ParentID, BoardID AS TopParent, 0 as versionModifier
        FROM    @Sample
        WHERE   ParentId = 0
    
        UNION ALL
    
        SELECT  s.boardID,s.UserCode,s.[Desc],s.ParentID, r.TopParent, -1 as versionModifier
        FROM    @Sample AS s 
        JOIN    recCTE AS r 
        ON      r.BoardId = s.ParentId
    )
    SELECT  boardID,UserCode,[Desc],ParentID, BoardID, 
            ROW_NUMBER() OVER (PARTITION BY TopParent
                                ORDER BY    boardId
                              )   + versionModifier AS [Version]
    FROM recCTE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table structure is below: CREATE TABLE [ACC].[Document]( [DocumentID] [int] IDENTITY(1,1) NOT NULL, [Date]
I have the schema below CREATE TABLE `vocabulary` ( `vid` int(10) unsigned NOT NULL
Please have a look at the schema below: CREATE TABLE Person (id int not
I am supporting code that has below schema declaration:- create table sample ( id
Table Schema For the two tables, the CREATE queries are given below: Table1: (file_path_key,
edit: my table schema below is poorly normalized as suggested and I have revamped
This is my table schema, below am is the schema for feedback table functionality,
I have the schema below : I tried to create a view and did
I have two tables names book_list and book_category . Schema is like below: book_list
I have the below table. I am trying to get tbody column bgcolors matching

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.