Author Posts

May 14, 2013 at 2:01 pm

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?

May 14, 2013 at 2:15 pm

This Stack Overflow post seems to have a LOT of good information on the topic:

May 14, 2013 at 2:29 pm

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.