This stored procedure script is useful for generating INSERT statements to insert data into a table that has an identity column. What I specifically had in mind when I wrote it was to backup a table for testing, run the tests, and then if I needed to revert the table back to its original state, I could truncate it and then re-insert from the backup table. When using the Management Studio's scripting tasks to create the insert statement, it wouldn't include the identity column. Also, you would have to add the "SELECT FROM" code to it. This spd basically combines all that into one call.
Example usage:
EXEC spd_Build_Insert_Into_Stmt_With_Identity 'Invoices_Backup', 'Invoices'
Results (as text in the results pane):
TRUNCATE TABLE Invoices
SET IDENTITY_INSERT Invoices ON
INSERT INTO Invoices (
Invoices_Id,
Yr_No,
Mth_No,
Billpayer_Id,
Acct_Nbr,
Call_Cnt,
Minute_Cnt,
Usage_Charge_Amt,
Reoccuring_Charge_Amt,
Non_Reoccuring_Charge_Amt,
Discount_Amt,
Tax_Amt,
Tot_Amt,
Last_Update_Dte,
Last_Update_User_Nm)
SELECT
Invoices_Id,
Yr_No,
Mth_No,
Billpayer_Id,
Acct_Nbr,
Call_Cnt,
Minute_Cnt,
Usage_Charge_Amt,
Reoccuring_Charge_Amt,
Non_Reoccuring_Charge_Amt,
Discount_Amt,
Tax_Amt,
Tot_Amt,
Last_Update_Dte,
Last_Update_User_Nm
FROM Invoices_Backup
SET IDENTITY_INSERT Invoices OFF