Sql 从视图导出数据

Sql 从视图导出数据,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,我正在SQL Server 2008上运行将向导导出到平面文件 我提供了此过程的查询,该过程从视图中获取数据: SELECT [Full Date] ,[Year Entered] ,[Month Entered] ,[Day Entered] ,[DOW] ,[Week Ending] ,[Accession] ,[Sales Rep] ,[MLNPI] ,[IMSNPI]

我正在SQL Server 2008上运行将向导导出到平面文件

我提供了此过程的查询,该过程从视图中获取数据:

SELECT [Full Date]
      ,[Year Entered]
      ,[Month Entered]
      ,[Day Entered]
      ,[DOW]
      ,[Week Ending]
      ,[Accession]
      ,[Sales Rep]
      ,[MLNPI]
      ,[IMSNPI]
      ,[IMS Specialty Primary Code]
      ,[Specialty Primary Description]
      ,[IMS Specialty Secondary Code]
      ,[Specialty Secondary Description]
      ,[IMS Specialty Tertiary Code]
      ,[Specialty Tertiary Description]
      ,[IMS Professional ID 1]
      ,[Physician]
      ,[Practice Code]
      ,[MLIS Code]
      ,[Practice Name]
      ,[Date Established]
      ,[Address]
      ,[Address2]
      ,[City]
      ,[State]
      ,[Status]
      ,[order count]
      ,[Order Comments]
      ,[Release Status]
  FROM [SalesDWH].[dbo].[BySpecimenWITHOUTLOMDATA]
  where [Year Entered]=2009
我发现以下错误:

- Validating (Error)
Messages
Error 0xc00470d4: Data Flow Task 1: The code page on input column "Full Date" (142) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "DOW" (146) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Week Ending" (147) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Accession" (148) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Sales Rep" (149) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "MLNPI" (150) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "IMSNPI" (151) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "IMS Specialty Primary Code" (152) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Specialty Primary Description" (153) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "IMS Specialty Secondary Code" (154) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Specialty Secondary Description" (155) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "IMS Specialty Tertiary Code" (156) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Specialty Tertiary Description" (157) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "IMS Professional ID 1" (158) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Physician" (159) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Practice Code" (160) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "MLIS Code" (161) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Practice Name" (162) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Address" (164) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Address2" (165) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "City" (166) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "State" (167) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Status" (168) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Order Comments" (170) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc00470d4: Data Flow Task 1: The code page on input column "Release Status" (171) is 1252 and is required to be 65001.
 (SQL Server Import and Export Wizard)

Error 0xc004706b: Data Flow Task 1: "component "Destination - 2009_txt" (106)" failed validation and returned validation status "VS_ISBROKEN".
 (SQL Server Import and Export Wizard)

Error 0xc004700c: Data Flow Task 1: One or more component failed validation.
 (SQL Server Import and Export Wizard)

Error 0xc0024107: Data Flow Task 1: There were errors during task validation.
 (SQL Server Import and Export Wizard)
有人知道我做错了什么,以及我如何解决这个问题吗

我试着用CAST来包装这些列:

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT cast( [Full Date] as nvarchar) as [Full Date],
cast([Year Entered] as nvarchar) as [Year Entered],
cast([Month Entered] as nvarchar) as [Month Entered],
cast([Day Entered] as nvarchar) as [Day Entered],
cast([DOW] as nvarchar) as [DOW],
cast([Week Ending] as nvarchar) as [Week Ending],
cast([Accession] as nvarchar) as [Accession],
cast([Sales Rep] as nvarchar) as [Sales Rep],
cast([MLNPI] as nvarchar) as [MLNPI],
cast([IMSNPI] as nvarchar) as [IMSNPI],
cast([IMS Specialty Primary Code] as nvarchar) as [IMS Specialty Primary Code],
cast([Specialty Primary Description] as nvarchar) as [Specialty Primary Description],
cast([IMS Specialty Secondary Code] as nvarchar) as [IMS Specialty Secondary Code],
cast([Specialty Secondary Description] as nvarchar) as [Specialty Secondary Description],
cast([IMS Specialty Tertiary Code] as nvarchar) as [IMS Specialty Tertiary Code],
cast([Specialty Tertiary Description] as nvarchar) as [Specialty Tertiary Description],
cast([IMS Professional ID 1] as nvarchar) as [IMS Professional ID 1],
cast([Physician] as nvarchar) as [Physician],
cast([Practice Code] as nvarchar) as [Practice Code],
cast([MLIS Code] as nvarchar) as [MLIS Code],
cast([Practice Name] as nvarchar) as [Practice Name],
cast([Date Established] as nvarchar) as [Date Established],
cast([Address] as nvarchar) as [Address],
cast([Address2] as nvarchar) as [Address2],
cast([City] as nvarchar) as [City],
cast([State] as nvarchar) as [State],
cast([Status] as nvarchar) as [Status],
cast([order count] as nvarchar) as [order count],
cast([Order Comments] as nvarchar) as [Order Comments],
cast([Release Status] as nvarchar) as [Release Status]


  FROM [SalesDWH].[dbo].[BySpecimenWITHOUTLOMDATA]
  where [Year Entered]=2009
并得到错误消息:

- Setting Source Connection (Error)
Messages
Error 0xc0207016: Source - Query [1]: There is a data source column with no name.  Each data source column must have a name.
 (SQL Server Import and Export Wizard)

Exception from HRESULT: 0xC0207016 (Microsoft.SqlServer.DTSPipelineWrap)
答案是将所有列更改为nvarchar数据类型。

Edit

错误消息中列的数据类型需要更改为
NVARCHAR
。由于您需要不修改视图,请在查询中使用来修改相应的列。我仍然会确保为目标文件指定
UTF-8
代码页只是为了保持一致性

原创

在导入/导出向导中,将文件目标的代码页更改为
65001(UTF-8)


谢谢你,布里奇。问题是我不想改变任何数据类型。当数据不是nvarcharbtw时,是否无法导出数据?我认为答案不对,因为我将查询改为选择CONVERT(nvarchar,[Full Date]),等等。。。。。还有同样的错误msgYou可以更改视图中的数据类型,而不是表模式-在视图定义中将每个列强制转换为nvarchar。恐怕我对这一领域的了解较低——但根据这一联系,没有其他办法;您需要unicode列类型。@对于所有具有非unicode文本数据类型的列,您都这样做了吗?您以前做得很正确-包装在cast或convert语句中出现错误的每一列。如果在所有类型转换都存在的情况下运行select查询,您是否收到结果或收到错误?@BlueFoots返回结果没有问题如果您从别名中的列名中删除空格,是否仍然收到错误?@BlueFoots是仍然收到错误!考虑试用BCP实用程序()而不是数据导出向导。对于这类工作,我使用它比使用笨重的U/I成功得多。该错误消息意味着在
转换后,其中一列的别名不正确。但是,我无法在您的查询中找到它,请仔细检查您使用的查询是否所有列都有别名。作为替代方法,请返回到
目标
窗口并选中
Unicode
复选框。在查询屏幕上,删除所有
CAST
功能。这行吗?在我使用
VARCHAR
datatype列进行测试时工作正常。