SQL has its own sequential generator
CREATE TABLE mytbl( ID int IDENTITY NOT NULL,
Mydata varchar(20) NOT NULL,
Mydata2 varchar(20) NOT NULL)
INSERT INTO mytbl(Mydata, mydata2)
VALUES ('some data', 'some more data')
to find out the value generated
SELECT SCOPE_IDENTITY()
[quoted text, click to view] "Bandit" <bandit@norge.no> wrote in message
news:uo82FDuVHHA.4764@TK2MSFTNGP05.phx.gbl...
>I have made a query to add a record with increasing sequence numbers, and
>it seems to work properly.
>
> insert into mytable (SequenceNumber)
> select max(SequenceNumber)+1 as SequenceNumber from transactiontable
>
> PROBLEM 1
> --------------
>
> However I also need to add some data to the other fields in the record,
> directly in the query:
>
> insert into mytable (SequenceNumber, Record2, Record3)
> select max(SequenceNumber)+1 as SequenceNumber from transactiontable,
> 'Text for record 2', 'Text for record 3'
>
> However, I do not understand how to do this. Any input is appreciated!
>
> PROBLEM 2
> --------------
>
> If possible, I would also like the query to return the value inserted into
> the SequenceNumber field of the current record.
>
>
>
> Bandit
>
>
>
>
>
>
>