SQL Server error "Xml data type is not supported in distributed queries" and workaround for it

Recently while working with data migration,got an error while running a following query where Server2 has beed added as linked server.

SELECT
*
FROM Server1.Database1.dbo.Table1
WHERE Column1 NOT IN
(SELECT Column1 FROM Server2.Database2.dbo.Table1)
GO

-- Error raised while run above query
"Xml data type is not supported in distributed queries. Remote object ‘Server2.Database2.dbo.Table1‘ has xml column(s)."

Server2.Database2.dbo.Table1 objects has another column named ‘column2‘ has xml datatype and we have not used it anywhere in query. We used ‘column1‘ of that table only and it has not xml datatype, even it has raised error. For the solution to avoid such error i have revised query as following.
SELECT
*
FROM Server1.Database1.dbo.Table1
WHERE Column1 NOT IN
    (
    SELECT
    	  *
    FROM
    OPENQUERY(Server2,‘
    			SELECT
    			Column1
    			FROM Database2.dbo.Table1‘
    		) linked
    )

这是网上查到的资料根据这个,我先把xml转化成nvarchar, 在转回去变成xml

SELECT top 100 [Internal Database ID],[Internal Database Search ID],[Watch List Code],[Watch List Description], CONVERT(xml, CAST([Watch List Record Detail] as nvarchar(max))) [Watch List Record Detail] FROM OPENQUERY( [172.16.4.169] ,
‘SELECT top 100 [Internal Database ID], [Internal Database Search ID],[Watch List Code],[Watch List Description], CAST([Watch List Record Detail] as nvarchar(max)) [Watch List Record Detail] FROM [VeridocsECCM].[dbo].[VML_View_WatchListHits]‘)

时间: 2024-10-14 23:37:41

SQL Server error "Xml data type is not supported in distributed queries" and workaround for it的相关文章

SQL Server 报错:com.microsoft.sqlserver.jdbc.SQLServerException: The "variant" data type is not supported.

查询 SQL SERVER 中某张表结构,sql 语句如下: SELECT tb.name AS tableName, col.name AS columnName, col.max_length AS length, col.is_nullable AS isNullable, t.name AS type, ( SELECT TOP 1 ind.is_primary_key FROM sys.index_columns ic LEFT JOIN sys.indexes ind ON ic.o

nodes() Method (xml Data Type)

https://docs.microsoft.com/en-us/sql/t-sql/xml/nodes-method-xml-data-type The nodes() method is useful when you want to shred an xml data type instance into relational data. It allows you to identify nodes that will be mapped into a new row. Every xm

Microsoft SQL Server, Error: 823 一次真实的经历

1,Case Description 有Dev skype 我,说在使用SSMS 打开DB的时候,报错 “The operating system returned error 59(An unexpected network error occurred.) to SQL Server during a read at offset 0x00000000474000 in file '\\Serveryyy\\xxxx.ndf'. Additional messages in the SQL

SQL SERVER中XML查询:FOR XML指定PATH

SQL SERVER中XML查询:FOR XML指定PATH 前言 在SQL SERVER中,XML查询能够指定RAW,AUTO,EXPLICIT,PATH.本文用一些实例介绍SQL SERVER中指定PATH的XML查询. PATH參数 PATH('參数'),參数是用来重命名ROW的,ROW是默认生成的名称. select 'Hui' for xml path  结果:<row>Hui</row> select 'Hui' for xml path ('root') 结果:<

SQL SERVER FOR XML PATH

转自:王波洋 (PS:对当前的博客进行了阅读,感觉不错,本来计划自己写一下,后来实在是时间不充裕并且博主写的不错,故转过来并稍微修正下) FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作. 一.FOR XML PATH 简单介绍           那么还是首先来介绍一下FOR XML PATH ,假设现在有一张兴趣爱好表(hobby)用来存放兴趣爱好,表结构如下:

灵活运用 SQL SERVER FOR XML PATH 转

灵活运用 SQL SERVER FOR XML PATH FOR XML PATH 有的人可能知道有的人可能不知道,其实它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作.那么以一个实例为主. 一.FOR XML PATH 简单介绍              那么还是首先来介绍一下FOR XML PATH ,假设现在有一张兴趣爱好表(hobby)用来存放兴趣爱好,表结构如下: 接下来我们来看应用FOR XML PATH的查询结果

使用SQL SERVER FOR XML PATH将多个结果集转换成一行并进行去重处理

在一个医药行业的系统中需要根据患者的接触记录ID获取不同接触类型的集合,效果像这样 --患者接触记录信息,一个患者可以有N个不同的接触记录,每个接触记录又有N个接触类型记录 IF OBJECT_ID ('dbo.TEST') IS NOT NULL DROP TABLE dbo.TEST GO CREATE TABLE dbo.TEST ( ID INT IDENTITY (1000,1) NOT NULL, cid INT,--接触记录号 REMARK VARCHAR (4000), CONT

Invalid object name ‘sys.configurations’. (Microsoft SQL Server, Error: 208)

http://blogs.msdn.com/b/ramaprasanna/archive/2009/09/16/invalid-object-name-sys-configurations-microsoft-sql-server-error-208.aspx ---------- When you use Microsoft SQL Server Management Studio 2008 to access SQL Azure, if you get the following error

SQL Server FOR XML PATH 语句的应用---列转行

经常在论坛看到高手使用了 for xml path,由于是搜索一下,记录了详细的使用方法.在SQL Server中利用 FOR XML PATH 语句能够把查询的数据生成XML数据,下面是它的一些应用示例. DECLARE @TempTable table(UserID int , UserName nvarchar(50));insert into @TempTable (UserID,UserName) values (1,'a')insert into @TempTable (UserID