尝试将数据从 SQL 获取到 Excel 时出错

尝试将数据从 SQL 获取到 Excel 时出错

我在 Excel 从 SQL 数据库读取 UniqueIdentifier 列时遇到问题。

在 excel 中,我转到数据 > 获取数据 > 从数据库 > 从 SQL 数据库。登录并连接到 SQL 数据库就好了。我可以看到我的表格,当我单击某个表格时,出现以下错误:

 DataSource.Error: Microsoft SQL: Conversion failed when converting from a character string to uniqueidentifier.
Details:
    DataSourceKind=SQL
    DataSourcePath=odin\act7;gfpact
    Message=Conversion failed when converting from a character string to uniqueidentifier.
    Number=8169
    Class=16

但是我可以使用相同的 GUID 格式来选择其他表。

我创建了 CREATE TO > New QUERY,以便您可以查看表属性

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[TBL_COMPANY](
    [COMPANYID] [uniqueidentifier] NOT NULL,
    [NAME] [nvarchar](128) NOT NULL,
    [DESCRIPTION] [nvarchar](128) NULL,
    [CATEGORY] [nvarchar](256) NULL,
    [REFERREDBY] [nvarchar](64) NULL,
    [TICKERSYMBOL] [nvarchar](12) NULL,
    [NUMEMPLOYEES] [int] NULL,
    [INDUSTRY] [nvarchar](64) NULL,
    [SICCODE] [nvarchar](8) NULL,
    [REVENUE] [decimal](18, 2) NULL,
    [TERRITORY] [nvarchar](64) NULL,
    [REGION] [nvarchar](64) NULL,
    [DIVISION] [nvarchar](64) NULL,
    [WEBADDRESS] [nvarchar](128) NULL,
    [HIERLEVEL] [int] NULL,
    [HIERPATH] [varchar](556) NULL,
    [HASSUBCOMPANY] [bit] NOT NULL,
    [CONTACTQUERYTEXT] [nvarchar](max) NULL,
    [OPPQUERYTEXT] [nvarchar](max) NULL,
    [QUERYVERSIONID] [uniqueidentifier] NOT NULL,
    [PARENTCOMPANYID] [uniqueidentifier] NULL,
    [ISPRIVATE] [bit] NOT NULL,
    [MANAGEUSERID] [uniqueidentifier] NOT NULL,
    [CREATEUSERID] [uniqueidentifier] NOT NULL,
    [CREATEDATE] [datetime] NOT NULL,
    [EDITUSERID] [uniqueidentifier] NULL,
    [EDITDATE] [datetime] NULL,
    [IMPORTDATE] [datetime] NULL,
 CONSTRAINT [TBL_COMPANY_PK] PRIMARY KEY CLUSTERED 
(
    [COMPANYID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 85) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

如何让 Excel 读取这些 UniqueIdentifier 列?

相关内容