Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    8

    Unanswered: Auto Increment on a Filed in a Table

    I have a table with two primary key fileds. I will be running a process to populate the data into the table.For each process the first field is constant and second field is auto increment one.

    My statements are insert into select ** from ** type one.

    How do I auto increment second filed per run. Any delivered function available or any suggestion Pl.................

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    It would help us answer you question a lot faster if you supplied DDL, sample Data, and the expected result...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Oct 2004
    Posts
    8
    DDL:
    Table1-

    id: PK
    lin_nbr: PK
    filed1
    field2

    Table2-

    filed1
    filed2
    filed3

    Data:


    insert into table1 (id, lin_nbr, filed1, filed2) (select 'a001', auto incr , field1,filed2 from table2 )

    Result in table2 should be


    a001 1 abc def
    a001 2 ghi jkl
    a001 3 xyz gfg

  4. #4
    Join Date
    Jan 2004
    Location
    In a large office with bad lighting
    Posts
    1,040
    Make your lin_nbr an identity column and when you insert, insert all but the lin_nbr column. SQL Server will auto-increment that column for you!

    Table1-

    id_col int not null,
    lin_nbr int identity not null,
    filed1 varchar(52) null, -- (or not null, whichever suits your purposes)
    field2 varchar(52) null -- (same applies)

  5. #5
    Join Date
    Oct 2004
    Posts
    8
    I want that increament is based on the another pk. pl have a look at the data below

    a001 1 abc def
    a001 2 ghi jkl
    a001 3 xyz gfg
    a002 1 abc def
    a002 2 ghi jkl
    a002 3 xyz gfg

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •