Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert job failing

Author  Topic 

donchamp
Starting Member

9 Posts

Posted - 2010-07-05 : 13:24:30
I'm executing the following code and it is failing. What am I missing?

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[TestDataTable](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Code] [varchar](10) NULL,
[Description] [varchar](100) NULL,
[ParentID] [int] NULL,
CONSTRAINT [ID] PRIMARY KEY CLUSTERED(
[ID] ASC))
GO
SET ANSI_PADDING OFF
--Insert Data into Testdatatable
SET IDENTITY_INSERT [master] . [ dbo ] . TestDataTable ON
INSERT INTO TestDataTable
SELECT Code, Description, ParentID FROM TEMPTABLE

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2010-07-05 : 15:13:34
What error are you getting?

There is no reason to set identity insert on, unless you are trying to insert a specific identity value. Remove that part, and specify the columns excluding the ID and it will work.

Example:

INSERT INTO TestDataTable (Code, Description, ParentID)
SELECT Code, Description, ParentID FROM TempTable;

Go to Top of Page
   

- Advertisement -