SQL Server Performance

Add Dummy Column in Query which increment itself

Discussion in 'General Developer Questions' started by d17may, May 15, 2007.

  1. d17may New Member

    I have table tble1 which has 2 columns
    I want to write query like which gives output like
    col1 col2 col3
    11 aa 1
    23 efd 2
    56 rt 3
    89 vg 4
    I need a third column which has autoincrement itself

  2. FrankKalis Moderator

    SELECT t.col1, t.col2, (SELECT COUNT(*) FROM tble1 WHERE col1 <= t.col1) AS col3
    FROM tble1 t

    Frank Kalis
    Microsoft SQL Server MVP
  3. Adriaan New Member

    DECLARE @t (col1 INT, col2 VARCHAR(3), col3 INT IDENTITY(1,1))

    INSERT INTO @t (col1, col2)
    SELECT col1, col2
    FROM MyTable

    SELECT * FROM @t
  4. Madhivanan Moderator

    Where do you want to show your data?
    If you use front end application, do numbering there


    Failing to plan is Planning to fail

Share This Page