• Why are you using dynamic SQL at all? Looks like that could just be two normal SQL statements, no dynamic necessary.

    Also, you don't have the sp_executeSQL call correct. There are three sections to the parameters for that sp, the query, the parameter definitions and the passing of values to the parameters. You're missing the third section.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass