Hmm... yeah that code is pretty old...This will do it:
EXEC dbo.sp_executesql @statement = N'ALTERPROCEDURE [dbo].[sp_ww_NewID]
@cName char(30),
@nRetval int OUTPUTASUPDATE wws_Id SET id = id + 1,
@nRetval = id + 1WHERE TableName = @cNameif @@ROWCOUNT< 1BEGINinsertinto wws_id (Tablename,Id) values (@cName,1)set @nRetval = 1END
'ENDGO
The code doesn't need to check for next id because the Update is a single statement that intrinsicly runs in a transaction. it's not possible for for two updates to run completely simultaneously on the same table while the table is looking at a specific value as it locks the record (or possibly even the entire table) during the update.
+++ Rick ---
Rick - I've noticed that the CreateNewId() method, when working with FoxPro DBF tables, will add the tablename to the ww_id table if it is not already present, but in Sql Server mode, it uses a stored proceure which does not add the table name to wws_id if it is not already present (like it does on the FoxPro datamode). It also does not attempt to verify that the next PK value is not already used in the target table, as it does for the FoxPro DBF version.
I'm moving my app from DBFs to Sql Server, and it looks like you've just got to manually prep the wws_id table with each table name and the correct next ID value to use.