I have a table that is used to store an incrementing numeric ID (of type INT). It contains a single row. The ID is incremented using a query:
UPDATE TOP(1) MyTable
WITH(TABLOCKX)
SET NextID = NextID + 1
I would like to move this into a stored procedure that returns the value that was in the NextID column before it was incremented, but am unsure how to do this using OUTPUT parameters. Any help would be appreciated.
for SQL Server 2005+, try:
the results of
OUTPUTdon’t need to go into an actual table, it can be a result set.test it out:
OUTPUT: