Click here to Skip to main content
15,905,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am inserting a roll number similar to 1ob-003-ee to a database column i want to know the last value inserted in the data base so that i can insert more data by adding 003 to 004 how can i do this . Can anybody provide me the query .
I am confused that should i use @identity to add data or some thing else please help me.
Posted

1 solution

SQL
DECLARE @ID INT


INSERT INTO TableName (Columns1, Column2) 
VALUES(Value1, Value2)

SET @ID = @@IDENTITY


--View Last inserted identity Value
SELECT @ID AS [Identity]

IDENTITY[^]
 
Share this answer
 
Comments
Sandeep Mewara 15-May-12 14:11pm    
My 5!
Maciej Los 15-May-12 14:19pm    
Thank you ;)
Sandeep Mewara 15-May-12 14:36pm    
Off Topic: Last night, I published a Tip: http://www.codeproject.com/Tips/384425/Server-side-Delimiters-in-ASP-NET Have a look and share your feedback.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900