Need Advice Please - Append or Temp Table or Other?

Posted on 2005-04-19
Last Modified: 2010-03-19
Hello Experts,
                   Here is my scenario. Front End: ASP VB Script. Backend: MS SQL 2000(Version 8). I am new to MS SQL so please bare with me. I have a Table (tblC_REPORT) with the following columns: Entry_ID(PK), CLIENT_ID(FK), ACNT_NUM, DISPUTE_ORDER.
Multiple report items for each client are entered into this table and I need to populate the DISPUTE_ORDER column with an Increment, i.e. 1-100. The increment must be associated with the CLIENT_ID.


  E01      |  C01        |   564858     |             1
  E02      |  C02        |   144545     |             2
  E03      |  C03        |   745825     |             3
  E04      |  D01        |   365458     |             1
  E05      |  D02        |   34558       |             2
Each row is entered individually. I do realize I could create a session and enter the DISPUTE_ORDER via a form increment based on inserts for that session, however I want this done all server side within the database.

I have thought of two possible scenarios but do not know how to execute them.
1) Create a Temporary Table and fill the increment there then pull the information over to the C_REPORT table.
2) Make another Table with a DISPUTE_ORDER column and list my increments there then append those integers into C_REPORT.DISPUTE_ORDER where Null equal to CLIENT_ID.

I would like to achieve my results by using a trigger or a stored procedure, however I do appreciate any suggestions you all may have.
I have been a member for a while, but this is my first question I have asked at EE. I would like to take this chance and thank everyone for this awsome community.
Thankyou to everyone here in advance for your help.
I am on a deadline and this is an urgent matter so here is 500 points.

Question by:Snapp
    LVL 68

    Accepted Solution

    Please try this:

    SET dispute_order = (
          SELECT COUNT(*)
          FROM tblC_REPORT rep2
          WHERE rep2.client_id = tblC_REPORT.client_id AND rep2.entry_id <= tblC_REPORT.entry_id


    Author Comment

    Thank you very much Scott for your fast response. It works flawlessly!
    Cheers :)

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
    Viewers will learn how the fundamental information of how to create a table.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now