Returning Identity with Invoke-Sqlcmd ?

Welcome Forums General PowerShell Q&A Returning Identity with Invoke-Sqlcmd ?

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
5 years, 9 months ago.

  • Author
    Posts
  • #4793

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

  • #4795

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘Returning Identity with Invoke-Sqlcmd ?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort