Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 ntext data type cannot be selected as DISTINCT

Author  Topic 

BabyAnn
Starting Member

10 Posts

Posted - 2008-03-03 : 04:23:21
Hello,
When I am using DISTINCT in the SELECT clause for a table having a column of datatype "ntext" in SQL 2000 as well SQL 2005, it fails giving the error as "ntext data type cannot be selected as DISTINCT". This is coz
"The text, ntext, or image data type cannot be selected as DISTINCT."

But I am able to insert into a temporary table having a column whose datatype is nvarchar) using this SELECT clause in SQL 2000. Please advice me how this happens. If I am not worng, implicit conversion has happened. But this insert fails raising the same error in SQL 2005. Please help me to find the difference
thanks in advance!

PeterNeo
Constraint Violating Yak Guru

357 Posts

Posted - 2008-03-03 : 05:31:28
Hi,

In SQL 2005 use cast(<colname> as NVARCHAR(MAX)) and use u r DISTINCT on the query.
About SQL 2000, I am not clear what u r doing?
Go to Top of Page

BabyAnn
Starting Member

10 Posts

Posted - 2008-03-03 : 06:04:26
Thanks for the information!

To be more clear,

CREATE TABLE TEST
(
WebDescription Ntext
)

INSERT INTO TEST (WebDescription) Values ('Test')
Select * from TEST
CREATE TABLE #List
(
WebDescription NVARCHAR(255),

)

INSERT INTO #List (WebDescription)
(
SELECT DISTINCT WebDescription FROM Test)


Select * from #List
--DROP TABLE #List
--DROP TABLE Test

The above statements got executed without any errors in SQL 2000.I would like to know why?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-03-03 : 07:38:08
I think this is the behavioural change in SQL Server 2005
See if you find the same
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/12/behaviour-changes-in-sql-server-2005.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -