Use
SCOPE_IDENTITY
not
Max(QuoteID)
.
Max(QuoteID)
will cause problems when simultaneous users create new quotes. It will work most of the time but it will give the wrong results if there are simultaneous
INSERT
statements from different users.
* See
Retrieving Identity or Autonumber Values (ADO.NET)[
^] in the Visual Studio Help.
SCOPE_IDENTITY
Returns the last identity value within the current execution scope. SCOPE_IDENTITY is recommended for most scenarios.
* See
SCOPE_IDENTITY [
^] in the Visual Studio Help.
Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, two statements are in the same scope if they are in the same stored procedure, function, or batch.