Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

I Have a table column eg (Invoice) invoice its(is Identity is on Increment by one)?

 

I Have a table column eg 

 

my project  contents invoice number as a filed when my data will be saved invoice number is auto increment after saving the data i want to print the Invoice , My Invoice Number Text Box is empty i dont know which number will be saved last time when i click on save button , how i can get the last saved number on my TextBox? can i get some information from seniors

user-image
Question ajoutée par Pathan Zarrar Khadar Khan , Windows System Administrator , Dyce Tech Pvt Ltd
Date de publication: 2016/10/10
Bhanu Pratap Singh
par Bhanu Pratap Singh , LEAD DATA ENGINEER , SYVEN GLOBAL SERVICES PVT. LTD.

  • @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes. You need to be careful here, since it's across scopes. You could get a value from a trigger, instead of your current statement.

  • SCOPE_IDENTITY() returns the last identity value generated for any table in the current session and the current scope. Generally what you want to use.

  • IDENT_CURRENT('tableName') returns the last identity value generated for a specific table in any session and any scope. This lets you specify which table you want the value from, in case the two above aren't quite what you need (very rare). Also, as @Guy Starbuck mentioned, "You could use this if you want to get the current IDENTITY value for a table that you have not inserted a record into."

  • The OUTPUT clause of the INSERT statement will let you access every row that was inserted via that statement. Since it's scoped to the specific statement, it's more straightforward than the other functions above. However, it's a little more verbose (you'll need to insert into a table variable/temp table and then query that) and it gives results even in an error scenario where the statement is rolled back. That said, if your query uses a parallel execution plan, this is the only guaranteed method for getting the identity (short of turning off parallelism). However, it is executed before triggers and cannot be used to return trigger-generated values.

Kais Hamdulay
par Kais Hamdulay , Technical Lead , Barclays

As invoice is auto increment you can retrieve the max value on invoice number form table + 1 which will give you the next new invoice number

Davidpaulraj Arulthomas
par Davidpaulraj Arulthomas , site reliability Engineer , Schlumberger

IDENT_CURRENT('tableName')  will give the last inserted record invoice number.

Shivashankari T
par Shivashankari T , Integration Testing Engineer , Wipro Technologies

Select Invoice from Table will retrieve the last updated value of the column as it's a autoincremented

More Questions Like This