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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:47:11+00:00 2026-06-06T03:47:11+00:00

I would like to create an integer counter for duplicate entries on an intermediate

  • 0

I would like to create an integer counter for duplicate entries on an intermediate table in an import step. Let’s say I have a table called FinalTable, which looks like this:

FinalTable

ID       Date          SameDateCounter
1003     2012/01/01    NULL
1004     2012/02/01    NULL
1005     2012/03/01    1
1006     2012/03/01    2
1007     2012/03/01    3
1008     2012/04/01    1
1009     2012/04/01    2

And has a unique constraint on (Date, SameDateCounter). In the intermediate step the data is in IntermediateTable, which looks exactly like FinalTable except that it doesn’t have any constraints. So the starting point for this problem is here:.

IntermediateTable:

ID       Date          SameDateCounter
1003     2012/01/01    NULL
1004     2012/02/01    NULL
1005     2012/03/01    NULL
1006     2012/03/01    NULL
1007     2012/03/01    NULL
1008     2012/04/01    NULL
1009     2012/04/01    NULL

And I need to generate the values for SameDateCounter, starting at one, where the date appears more than once.

  • 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-06T03:47:13+00:00Added an answer on June 6, 2026 at 3:47 am

    You can use the ROW_NUMBER() function combined with a PARTITION BY clause:

    ;WITH Data AS
    (  
       SELECT
           ID, Date,
           SameDateCounter = ROW_NUMBER() OVER (PARTITION BY Date ORDER BY ID DESC)
       FROM dbo.YourTableNameHere
    )
    SELECT *
    FROM Data
    

    The PARTITION BY Date clause groups every separate value of Date into its own “partition”, and ROW_NUMBER() hands out numbers starting at 1, for each partition.

    So your SameDayCounter will start at 1 for each new day and will show the rows for that particular day.

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

Sidebar

Related Questions

I have a table that looks something like this: CREATE TABLE student_results(id integer, name
i would like create a array of structure which have a dynamic array :
I would like to create a game like crosswords, which will have a drag
I would like to create new instances of my Class called Item inside a
I have an events based table that I would like to produce a query,
I would like to create a compound component that consists of a TextView (integer
I would like to create a function for a table that has three columns
I have a table (Oracle database) that looks like: CREATE TABLE example ( idEx
I would like to create a table in a SQLite database using the Server
I have two tables like this: CREATE TABLE table1_lang ( id serial NOT NULL,

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.