You can create a stored procedure like this
.
.
.
CREATE PROCEDURE [insert_something]
/* put your insert variables here*/
@data1 varhar(100)
@data2 varchar(100)
AS
declare @newId int
select @newId = last_id + 1
from table_name
where --......
update table_name set
last_id = @newId
where --.....
insert into table_name(
EmpID,
column1,
column2
)
values (
@newId,
@data1,
@data2
)
Modify this to suit you.
hope it helps.
-----Original Message-----
From: ann win [mailto:awin@a...]
Sent: Thursday, October 12, 2000 7:00 PM
To: sql language
Subject: [sql_language] error in inserting into identity field
Hi,
My SQL table has identity field called EmpID. So, when I insert, I
left out the EmpID like this.
INSERT INTO P1Payroll (SurveyID, empName, JobCode,GAP, PFT,
hrlywage,tphryr, tphryrVac, benDlr, benPct)VALUES(\'P1CA0100\',\'ann
win\',\'01\',40,99,25,49,90,90099,99)
It work fine in my development server. But When I uploaded to the
server that I rent for production, I got the following error message.
Error: -2147217900
description: [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert
the value NULL into column \'EmpID\', table
\'neilscos.neilscos.p1Payroll\'; column does not allow nulls. INSERT
fails.
Tech support says I cannot use idendity fields to produce autonumbers
and I need to write the code to produce auto numbers. It does not sound
right. May be he is right. If he is correct, how can I write the code?
Thanks in advance.
-ann