sql-server - 将查询结果导出到 Excel Microsoft SQL Server 2012 时找不到源数据类型 "200"错误

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

我对 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.

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

最佳答案

因此,在您提供的 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是表名。

仅供引用,在 之后第一次你已经执行了上述——在你“创建”了 View 之后——然后从那时起, View 的第一行(修改期间)从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 导出(或您选择的任何表名)。

希望有帮助...

关于sql-server - 将查询结果导出到 Excel Microsoft SQL Server 2012 时找不到源数据类型 "200"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22460278/

相关文章:

r - 在 SQL Server 中组合 dbplyr 和 case_when

python - 从 .h5 文件写入 excel : performance

java excel读取一列

sql - GMT 到 EST 时区转换 SSIS/SQL Server

c# - 在 C# 中刷新 Excel 工作表

java - 用于实现 DBMS 的数组/列表 (Java)

sql - 使用 SQL 克隆数据库中表示的树结构

excel - 使用 Interop.Excel 将 Excel 转换为 PDF 时不显示图像

c# - 将数据从 AD 拉入数据库的 SSIS 脚本任务

sql-server - SSIS 包是否失败,当其中一个容器失败时