views:

52

answers:

1

I am transfering data from an old database to a new one, and I need to keep the ID from the old database when inserting them into the new database. However, it's not working.

This is my Query:

SET IDENTITY_INSERT RentalEase.dbo.tblTenant ON
INSERT INTO RentalEase.dbo.tblTenant SELECT [ID]
    ,1
      ,[PropertyID]
    ,0
      ,[UnitID]
      ,[TenantName]
      ,[Sex]
      ,[BirthDate]
      ,[SSNO]
      ,[CoTenant1]
      ,[CoTenant1Sex]
      ,[CoTenant1BirthDate]
      ,[CoTenant1SSNO]
      ,[CoTenant2]
      ,[CoTenant2Sex]
      ,[CoTenant2BirthDate]
      ,[CoTenant2SSNO]
      ,[CoTenant3]
      ,[CoTenant3Sex]
      ,[CoTenant3BirthDate]
      ,[CoTenant3SSNO]
      ,[CarColor]
      ,[CarModel]
      ,[CarYear]
      ,[CarState]
      ,[CarPlateNumber]
      ,[Memo]
      ,[Address1]
      ,[Address2]
      ,[Address3]
      ,[Address4]
      ,[Phone]
      ,[ReferBy]
      ,[BeginDate]
      ,[NoticeGiven]
      ,[LeaseMonth2Month]
      ,[LeaseEnds]
      ,[DepositPaid]
      ,[DepositRefundable]
      ,[RefundMemo]
      ,[RentDueDay]
      ,[Charge1]
      ,[Charge1Amount]
      ,[Charge2]
      ,[Charge2Amount]
      ,[Charge3]
      ,[Charge3Amount]
      ,[Charge4]
      ,[Charge4Amount]
      ,[ContractText]
      ,[BalanceDue]
  FROM [oldTables].[dbo].[tblCurrentTenant]

  SET IDENTITY_INSERT RentalEase.dbo.tblTenant OFF

SQL Server complains that "An explicit value for the identity column in table RentalEase.dbo.tblTenant' can only be specified when a column list is used and IDENTITY_INSERT is ON."

What do I need to do to get it to work?

+6  A: 

"An explicit value for the identity column in table RentalEase.dbo.tblTenant' can only be specified when a column list is used and IDENTITY_INSERT is ON."

So use a column list, as the message states:

SET IDENTITY_INSERT RentalEase.dbo.tblTenant ON
INSERT INTO RentalEase.dbo.tblTenant ([ID], [fieldname], [fieldname], ...)
SELECT [ID], ...
Remus Rusanu
You beat me to it. Exactly what I was going to say.
HLGEM