• I don't know if it was apparent from the previous posts but you should be fine if you change this

    SELECT @sql = 'SET IDENTITY_INSERT ' + @tablename + ' OFF'

    to this

    SELECT @sql = 'SET IDENTITY_INSERT ' + @tablename + ' ON'

    in your code.

    Actually you should also include this

    SELECT @sql = 'SET IDENTITY_INSERT ' + @tablename + ' OFF'

    EXEC (@sql)

    into your script after you perform the insert to set the setting back the way it was.

    The reason some tables work and some don't is that the tables that work do not have identity columns. The others do and the query blows up.

     

    ---------------------------------------------
    [font="Verdana"]Nothing is impossible.
    It is just a matter of time and money.[/font]