【问题标题】:SQL Server, "Invalid column name" error when inserting into Excel "linked server"SQL Server,插入 Excel“链接服务器”时出现“列名无效”错误
【发布时间】:2014-03-27 18:07:18
【问题描述】:

我有一个简单的 Excel 电子表格文档(运行 Office 2013),我将其用作使用“Microsoft Office 15.0 Access Database Engine OLE DB Provider”的数据库。

我可以使用 MS SQL Server Management Studio 2012 连接到此,我什至可以从命名范围“员工”中选择数据。

SELECT *
  FROM [X]...[Employee]
GO

结果:

ID  Name    Description Salary
1   Rob     Cool        1
2   Bob     Awesome     2
3   Robert  DUDE!       3

现在我想在这里插入数据。于是我写了:

INSERT INTO [X]...[Employee]
           ([ID]
           ,[Name]
           ,[Description]
           ,[Salary])
     VALUES
           (4
           ,"John"
           ,"Boss"
           ,500)

这实际上主要由 SQL Server Management Studio 生成。当我运行它时,我得到:

Msg 207, Level 16, State 1, Line 8
Invalid column name 'John'.
Msg 207, Level 16, State 1, Line 9
Invalid column name 'Boss'.

知道我做错了什么吗?

【问题讨论】:

    标签: sql-server excel oledb


    【解决方案1】:

    您使用的是双引号而不是单引号。即:

    INSERT INTO [X]...[Employee]
           ([ID]
           ,[Name]
           ,[Description]
           ,[Salary])
     VALUES
           (4
           ,'John'
           ,'Boss'
           ,500)
    

    【讨论】:

    • 捂脸!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多