RECORDID I <Indenty Column> TableName VarChar (5) LastID II'd like to be able to create a stored procedure on the SQL server that I can pass it the table name and get the next id, if there is no record in for that table insert a record and return 1 as the lastid
CREATE procedure sp_Next_id @tablename varchar, @nreturn int output as declare @nLastID int select nlastid=lastid from schid where tablename=@tablename if @@rowcount = 0 set @nreturn=1 set @nlastid=1 insert into schid (tablename,lastid) values (@tablename,@nlastid) GOI Call it with:
lccmd=[exec sp_next_id "CT_PAT",?@nNextID] ? SQLEXEC(gnConnHandle,lcCmd)This starts to work, but always only stores the 1st character of the table name to the schid table, thus if I run the same command again, it doesn't find a match.
CREATE procedure sp_Next_id @tablename varchar, @nreturn int output as declare @nLastID int select nlastid=lastid from schid where tablename=@tablename if @@rowcount = 0 set @nreturn=1 set @nlastid=1 insert into schid (tablename,lastid) values (@tablename,@nlastid) GO else set @nReturn=@nlastID+1 update schid set lastID=@nLastIDAny Help Appreciated