【问题标题】:Source data type "200" not found error when exporting query results to excel Microsoft SQL Server 2012将查询结果导出到 Excel Microsoft SQL Server 2012 时找不到源数据类型“200”错误
【发布时间】:2014-03-17 16:46:30
【问题描述】:

我对 Microsoft SQL Server 非常陌生,并且正在使用 2012 Management Studio。当我尝试使用向导将查询结果导出到 Excel 文件时,出现上述错误。我在其他地方看到过针对此错误发布的解决方案,但不知道如何实施推荐的解决方案。有人可以逐步指导我完成这些解决方案之一吗?

我认为我的问题是 SQL Server 导入和导出向导无法识别 Varchar 和 NVarchar,我认为这是我收到错误的列的数据类型。

Source Type 200 in SQL Server Import and Export Wizard?

http://connect.microsoft.com/SQLServer/feedback/details/775897/sql-server-import-and-export-wizard-does-not-recognise-varchar-and-nvarchar#

查询:

SELECT     licenseEntitlement.entID, licenseEntitlement.entStartDate, entEndDate, quote.quoteId, quote.accountId, quote.clientId, quote.clientName, quote.contactName, 
                      quote.contactEmail, quote.extReference, quote.purchaseOrderNumber, quote.linkedTicket
FROM         licenseEntitlement INNER JOIN
                      quote ON quote.quoteId = SUBSTRING(licenseEntitlement.entComments, 12, PATINDEX('% Created%', licenseEntitlement.entComments) - 12)
inner join sophos521.dbo.computersanddeletedcomputers on computersanddeletedcomputers.name = entid and IsNumeric(computersanddeletedcomputers.name) = 1
WHERE     (licenseEntitlement.entType = 'AVS') AND (licenseEntitlement.entComments LIKE 'OV Order + %') and entenddate < '4/1/2014' 
ORDER BY licenseEntitlement.entEndDate

错误:

TITLE: SQL Server Import and Export Wizard
------------------------------

Column information for the source and the destination data could not be retrieved, or the data types of source columns were not mapped correctly to those available on the destination provider.


[Query] -> `Query`:

          - Column "accountId": Source data type "200" was not found in the data type mapping file.
          - Column "clientId": Source data type "200" was not found in the data type mapping file.
          - Column "clientName": Source data type "200" was not found in the data type mapping file.
          - Column "contactName": Source data type "200" was not found in the data type mapping file.
          - Column "contactEmail": Source data type "200" was not found in the data type mapping file.
          - Column "extReference": Source data type "200" was not found in the data type mapping file.
          - Column "purchaseOrderNumber": Source data type "200" was not found in the data type mapping file.
          - Column "linkedTicket": Source data type "200" was not found in the data type mapping file.

如果需要更多详细信息,请告诉我

【问题讨论】:

  • 我认为你需要显示你运行的查询,描述返回的列的数据类型,描述你导出结果的步骤和你得到的错误。这里没有人会做你想做的事 - 如果我不能在 5 分钟内回答,除非我个人感兴趣,否则我可能不会 - 我们没有人为此得到报酬,你的问题需要付出大量的努力没有明确的限制。
  • 已添加 SSIS 标记:Mgmt Studio 中的导出数据向导正在运行 SSIS (SQL Server Integration Studio),因此这是一个 SSIS 错误。不过,西蒙是对的:我们需要更多细节。我建议先向我们提供错误消息的完整且准确的文本。而且,由于data type 是列的属性,请告诉我们您可以对这些列做些什么。
  • 感谢您的回复,我添加了详细信息。我认为可能有一个简单的解决方法,可以用简单的术语解释,由于我在这里的知识有限,技术性不太强。如果不是这种情况,请告诉我,我可以删除问题。再次感谢。
  • 首先,Microsoft 承认这是导入/导出向导中的一个已知错误。其次,所有链接中推荐的解决方法是将您的查询转换为视图,然后从 that 导出。为什么不能实现呢?

标签: sql-server excel ssis sql-server-2012 ssms


【解决方案1】:

因此,在您提供的 StackOverflow 链接上实施建议,将查询转换为 View,这是一个示例(带有一些代码格式;)--

CREATE VIEW [dbo].[test__View_1]
AS
SELECT LIC.entID, LIC.entStartDate, entEndDate, 
    quote.quoteId, quote.accountId, quote.clientId, quote.clientName, 
    quote.contactName, quote.contactEmail, quote.extReference, 
    quote.purchaseOrderNumber, quote.linkedTicket
FROM [dbo].licenseEntitlement  LIC  WITH(NOLOCK)
    INNER JOIN [dbo].quote  WITH(NOLOCK)
        ON quote.quoteId = SUBSTRING(LIC.entComments, 12, 
            PATINDEX('% Created%', LIC.entComments) - 12)
    INNER JOIN sophos521.dbo.computersanddeletedcomputers  COMPS  WITH(NOLOCK)
        ON COMPS.name = entid and IsNumeric(COMPS.name) = 1
WHERE (LIC.entType = 'AVS') 
  AND (LIC.entComments LIKE 'OV Order + %') 
  and (entenddate < '4/1/2014')
ORDER BY LIC.entEndDate

GO

然后,您将从test__View_1(或您为其选择的任何真实名称)导出,就好像test__View_1 是表名一样。

仅供参考,在第一次执行上述操作之后——在你“创建”视图之后——然后从那时起,视图的第一个行(修改期间)从CREATE VIEW 更改为ALTER VIEW

((而且,除了错误问题...在您的WHERE 子句中,您是打算entComments LIKE 'OV Order + %',还是真的打算成为entComments LIKE 'OV Order%'?我已经做出了改变,或者示例代码,如下。))

注意:如果您要重复地 导出(或重复使用)一次运行的输出,特别是如果您的查询速度很慢或占用机器...那么而不是VIEW,您可能更喜欢 SELECT INTO,创建一个表一次,可以快速重复使用。 (在为导出开发一次性查询时,我也会选择SELECT INTO 而不是CREATE VIEW。)

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES
            WHERE TABLE_NAME = 'zz_LIC_ENT_DETAIL')
    DROP TABLE [dbo].zz_LIC_ENT_DETAIL

SELECT LIC.entID, LIC.entStartDate, LIC.entEndDate, 
    quote.quoteId, quote.accountId, quote.clientId, quote.clientName, 
    quote.contactName, quote.contactEmail, quote.extReference, 
    quote.purchaseOrderNumber, quote.linkedTicket
INTO [dbo].zz_LIC_ENT_DETAIL
FROM [dbo].licenseEntitlement  LIC  WITH(NOLOCK)
    INNER JOIN [dbo].quote  WITH(NOLOCK)
        ON quote.quoteId = SUBSTRING(LIC.entComments, 12, 
            PATINDEX('% Created%', LIC.entComments) - 12)
    INNER JOIN sophos521.dbo.computersanddeletedcomputers  COMPS  WITH(NOLOCK)
        ON COMPS.name = LIC.entid and IsNumeric(COMPS.name) = 1
WHERE (LIC.entType = 'AVS') 
  AND (LIC.entComments LIKE 'OV Order%') 
  and (LIC.entenddate < '4/1/2014')
ORDER BY LIC.entEndDate

然后,您当然会从表 zz_LIC_ENT_DETAIL(或您选择的任何表名)导出。

希望对您有所帮助...

【讨论】:

    【解决方案2】:

    右键单击查询结果窗口并选择将结果另存为 (CSV) 可能更容易。

    要在第一行附加列名,您还需要以这种方式修改查询(注意 int 或 datetime 列的强制转换):

    select 'col1', 'col2', 'col3'
    union all
    select cast(id as varchar(10)), name, cast(someinfo as varchar(28))
    from Question1355876
    

    【讨论】:

    • 注意:如果您正在处理数百万行,这将不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多