使用“ INSERT INTO”时如何解决错误?

时间:2019-06-26 12:39:54

标签: sql-server

我正在尝试将整个表放到另一个表中。列数,它们的名称和类型完全相同。 由于某种原因,我无法完成此操作。

Case_Data表:

Case_Data Table

POC_CD表:

POC_CD Table

代码:

insert into [dbo].[POC_CD] select * from [dbo].[Case_Data]

错误:

  

消息241,级别16,状态1,行1转换时转换失败   字符串中的日期和/或时间。

编辑:为两个表创建表代码

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[POC_CD](
    [Case Type] [nvarchar](255) NULL,
    [Category] [nvarchar](255) NULL,
    [Client] [nvarchar](255) NULL,
    [L2/L3 User] [nvarchar](255) NULL,
    [Number] [nvarchar](255) NULL,
    [Opened] [datetime] NULL,
    [Organization] [nvarchar](255) NULL,
    [Priority] [nvarchar](255) NULL,
    [Product] [nvarchar](255) NULL,
    [Resolved] [datetime] NULL,
    [Resolution Code] [nvarchar](255) NULL,
    [Scheduled Follow Up] [datetime] NULL,
    [State] [nvarchar](255) NULL,
    [Subcategory] [nvarchar](255) NULL,
    [TicketSummary] [nvarchar](255) NULL,
    [Updated] [datetime] NULL
) ON [PRIMARY]

GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Case_Data](
    [Number] [nvarchar](255) NULL,
    [State] [nvarchar](255) NULL,
    [Priority] [nvarchar](255) NULL,
    [Organization] [nvarchar](255) NULL,
    [Client] [nvarchar](255) NULL,
    [Product] [nvarchar](255) NULL,
    [Category] [nvarchar](255) NULL,
    [Subcategory] [nvarchar](255) NULL,
    [Ticket Summary] [nvarchar](255) NULL,
    [Case Type] [nvarchar](255) NULL,
    [Resolved] [datetime] NULL,
    [Opened] [datetime] NULL,
    [Scheduled Follow Up] [datetime] NULL,
    [Resolution code] [nvarchar](255) NULL,
    [L2/L3 User] [nvarchar](255) NULL,
    [Updated] [datetime] NULL
) ON [PRIMARY]

GO

1 个答案:

答案 0 :(得分:0)

see here

您必须像这样编辑列的顺序:

Insert into [dbo].[POC_CD](  [Number] ,[State] ,[Priority],[Organization] ,[Client] ,[Product] ,[Category] ,[Subcategory],[Ticket Summary] ,[Case Type] ,[Resolved] ,[Opened] ,[Scheduled Follow Up] ,[Resolution code] ,[L2/L3 User] ,[Updated])
select   [Number]
 [Number] ,[State] ,[Priority],[Organization] ,[Client] ,[Product] ,[Category] ,[Subcategory],[Ticket Summary] ,[Case Type] ,[Resolved] ,[Opened] ,[Scheduled Follow Up] ,[Resolution code] ,[L2/L3 User] ,[Updated] from [dbo].[Case_Data]

在插入列和选择列之间具有相同的顺序