February 24, 2014 at 3:19 am
Can we write a stored procedure , which will return different value each time , incremented by 1
Like first time we call the stored procedure , it should return 1
seond time , it should return , 2
thrd time , it should return 3
4th time , it should return 1
5th time , it should return 2
6th time , it should return 3 .
So after every 3rd call, it should return 1
February 24, 2014 at 3:23 am
Kinda, create a table to store the value and increment/decrement the value as appropriate when the procedure is called. You'll have to watch locking/isolation levels to ensure the correct results when two or more connections call the procedure simultaneously.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
February 24, 2014 at 3:34 am
You can also use SEQUENCE feature of SQL Server to get this functionality. However SEQUENCE are only available from SQL Server 2012 onwards.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply