Skip to content
Advertisement

Stored Procedure return default value?

in my database, there is a Stored Procedure with INSERT INTO statement. The problem is I want this stored procedure will return the StudentCode default value, I think it’s impossible to use the SELECT TOP 1 statement to get this value because there may be multiple rows inserted at the same time. Any help or suggestions?. Thanks very much

Advertisement

Answer

Use OUTPUT INSERTED clause, as explained into official docs:-

INSERTED

Is a column prefix that specifies the value added by the insert or update operation. Columns prefixed with INSERTED reflect the value after the UPDATE, INSERT, or MERGE statement is completed but before triggers are executed.

so your code is going to be like this:- (is not tested, but it guides you to accurate code)

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement