Returning Identity with Invoke-Sqlcmd ?

This topic contains 2 replies, has 2 voices, and was last updated by  Kitt Holland 5 years, 2 months ago.

  • Author
  • #4793

    Kitt Holland

    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?

  • #4794

    Jeffrey Smith

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

  • #4795

    Kitt Holland

    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.

You must be logged in to reply to this topic.