Results 1 to 2 of 2

Thread: How to create a number of record in an SQL query?

  1. #1
    Join Date
    Jul 2004
    Location
    Saransk, Russia
    Posts
    6

    Question How to create a number of record in an SQL query?

    Tell me please how to get the sequental number of record in query. I need to create a query that contains a field in that is the sequental number of the record in the query. I've found an idea only how to do it in update but I need it in insert. Update after insert is impossible because I need to store such number of record into a primary key. That idea consists in using construnction @intCounter = fieldname = @intCounter + 1 but insert operator can't use = operator. I need in this query insert into one table data selected from other one. The function INDENTITY requires SELECT INTO construction that as I've understood going to create new table but I need to add into existing table so such construction I don't know how to make working.

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    You can create an INDENTITY column on the table and it will automatically populate the table rows with sequential values.

    Use ALTER TABLE ...

Posting Permissions

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