简体   繁体   English

从链接服务器复制表

[英]Copy table from linked server

I was trying to copy a table from a view in linked server with the following script:我试图使用以下脚本从链接服务器的视图中复制一个表:

SELECT 
    [order_no]
    , [cust_code]
    , [order_date]
    , [order_status]
    , [reference]
INTO dbo.Sales
FROM [BIT].[bit].[BI].[sales_order]

I got the error below:我收到以下错误:

Cannot get the data of the row from the OLE DB provider for linked server "BIT".无法从链接服务器“BIT”的 OLE DB 提供程序获取行数据。 Could not convert the data value due to reasons other than sign mismatch or overflow.由于符号不匹配或溢出以外的原因,无法转换数据值。

The script runs well if I remove the [reference] column.如果我删除 [reference] 列,脚本运行良好。 I have checked the data type and it is matched.我已经检查了数据类型并且它是匹配的。

What can I do if I really want the reference column to be in the table?如果我真的想让引用列在表中怎么办? I have tried to copy only the reference column and it is failed as well with the same error message.我试图只复制参考列,但也失败了,并显示相同的错误消息。

See this stackoverflow post which shows how to find invalid characters in SQL fields请参阅此stackoverflow 帖子,其中显示了如何在 SQL 字段中查找无效字符

For your table this is what you'd use to find invalid characters in the reference field:对于您的表格,这是您用来在参考字段中查找无效字符的内容:

select [reference],
  patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,[reference]) as [Position],
  substring([reference],patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,[reference]),1) as [InvalidCharacter],
  ascii(substring([reference],patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,[reference]),1)) as [ASCIICode]
from  dbo.Sales
where patindex('%[^ !-~]%' COLLATE Latin1_General_BIN,[reference]) >0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM