I'm building a generic parameterized query (INSERT, or UPDATE) and I'm using parameters for the inserted columns (in the INSERT query) and parameters for the updated columns and the where clause columns (in the UPDATE query).
In either case, I also allow for a column name to be specified which is returned by my method, and to accomplish that I'm using OUTPUT INSERTED.ColumnName
. This column could be the primary key of the table, but it could be also something else.
Now, after doing the INSERT or UPDATE, I want to obtain the key of the row that was just inserted or updated. How can I do this? Can I do something like OUTPUT INSERTED.ColumnName, SCOPE_IDENTITY()
?
Note: This is NOT a stored procedure, in case that matters.