I’m doing an insert into a MSSQL 2012 database using the SQLPS module and Invoke-Sqlcmd. The table I’m inserting into has an auto-incrementing identity column. Does anyone know how to return or select the identity of the row that I inserted?
This Stack Overflow post seems to have a LOT of good information on the topic:
http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row
Thanks for the link, I did look at that thread and Scope_Identity always returned NULL for me. I assume because it’s occurring as a separate session/connection since I have to do a separate Invoke-Sqlcmd -query “Select Scope_Identity();”. If that is the correct way I’m not sure what the syntax would be.