Field with autonumeric

  • There is anyway to do this running a single statment??

    I need return the data like this:

     

    counter       Clientname

    1                a

    2                b

    3                c

    4                d

    I have the clientname but I don't have the counter, How do I add this running a single script?

    thanks

     

  • Why can't you use the application to display the row count?

  • this statement is from a view

  • And the view is only used on the server???

     

    Can you give more details on what you are trying to accomplish, it would greatly help us provide the best solution.

  • I need a primary key on that view and the 2 tables involved there is no primary key, and I don't know how to do that.

  • Again WHY????

     

    Explain from A to Z what you need to do.  There are way too many possibilities for me to start answering that question.

  • that view provide details of the invoices, but the invoice table doesn't have a primary key, the application do not accept it, I try to modify and I shut down the company, so the problem is on a grid of asp.net if I click details it keep saying that I need a primary key to view the details, so I;m trying to come up with a solution for that.

    hope this help you understanding my dilema

  • and the original table is on AS400, I create that view using the OPENQUERY script, and I cannot change nothing on AS400

  • Yes it does.  But just creating a fake primary key on a view will not fix the problem.  You need to create a primary key on the table(s) displayed in the datagrid.  Otherwise you won't be able to do anything (with almost any tools for that matter).

     

    If you need help fixing the design, I suggest you start a new thread and post the link to it in a new post in this thread (get most exposure).

  • This might help you (SQL Server) 

    DECLARE @tbl TABLE (C VARCHAR(10))

    INSERT INTO @tbl VALUES ('zzz')

    INSERT INTO @tbl VALUES ('abc')

    INSERT INTO @tbl VALUES ('abc')

    INSERT INTO @tbl VALUES ('xxx')

    INSERT INTO @tbl VALUES ('rtt')

    INSERT INTO @tbl VALUES ('www')

    INSERT INTO @tbl VALUES ('ccc')

    SELECT T2.C,(SELECT COUNT(1) FROM (SELECT DISTINCT C FROM @tbl) AS T1 WHERE T1.C <= T2.C) AS UniqueId

    FROM (SELECT DISTINCT C FROM @tbl) AS T2

    ORDER BY 2

  • Wouldn't that be what the invoice number is for? 

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply