SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Can't select DISTINCT values with XML datatype.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

NguyenL71
Posting Yak Master

USA
206 Posts

Posted - 10/22/2013 :  12:05:15  Show Profile  Reply with Quote
I have a table with a lot of dup values and I need to select DISTINCT values from this table and put into temp and delete records
in the original table and re-insert distinct values from temp into this table but getting an error because it has XML datatype
in one of the column, the table is CDC and has not PK. How can I get around this?. Is there an other way to get
distinct values from the table?. SQL 2012.

I appreciate your help.


/****** Object: Table [HIX].[dbo_PMPMRate_CT] Script Date: 10/22/2013 8:44:28 AM ******/
SET ANSI_NULLS ON

CREATE TABLE [abc].[dbo_TestRate_CT]
(
[__$start_lsn] [binary](10) NOT NULL,
[__$seqval] [binary](10) NOT NULL,
[__$operation] [int] NOT NULL,
[__$update_mask] [varbinary](128) NOT NULL,
[PMPMRate_ID] [int] NULL,
[Entity_ID] [bigint] NULL,
[CreateDate] [datetime] NULL,
[UpdateDate] [datetime] NULL,
[PlanCatelogSettings] [xml] NULL,
[Effective_date] [datetime] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO


SELECT DISTINCT *
FROM abc.dbo_TestRate_CT;
GO

-- Error:
Msg 421, Level 16, State 1, Line 1
The xml data type cannot be selected as DISTINCT because it is not comparable.


James K
Flowing Fount of Yak Knowledge

3326 Posts

Posted - 10/22/2013 :  13:04:04  Show Profile  Reply with Quote
Couple of thoughts come to mind, but none of them perfect:

1. If you don't care about the distinctness of the XML column, exclude that column from your distinct clause.
2. Cast the XML column as varchar(max) and then look for distinctness. However, this is not safe because logically identical XML fragments may not produce identical strings when you cast.
3. Shred the XML column into relational data and put that together with the other columns and look for distinctness.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000