Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Grouptext, ntext, and image data types cannot be compared or sorted

Tags:

sql

sql-server

Below is an sql statement and an error I'm receiving. I want to group all returned items by the prodID.

Error:

The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

Statement:

 SELECT TOP 20 
         PRODID, ITEMDES
         FROM orderedItems oi
         left join orders o on  oi.order_id = o.order_id
    Group by PRODID, ITEMDES
like image 985
Prometheus Avatar asked Aug 31 '12 14:08

Prometheus


People also ask

Which data type Cannot be sorted?

The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

What is Ntext data type in SQL Server?

NTEXT is a variable-length data type that can store long Unicode character strings. NTEXT can hold up to 2,147,483,647 bytes of data. The actual storage used depends on the length of the character string. Note: NTEXT has been deprecated and will be removed in some future release of SQL Server.

When might you use Ntext instead of Nvarchar?

ntext will always store its data in a separate database page, while nvarchar(max) will try to store the data within the database record itself. So nvarchar(max) is somewhat faster (if you have text that is smaller as 8 kB). I also noticed that the database size will grow slightly slower, this is also good.

What is the difference between text and Ntext in SQL?

Text - Variable-length non-Unicode data with a maximum length of 2^31 - 1 (2,147,483,647) characters. nText - Variable-length Unicode data with a maximum length of 2^30 - 1 (1,073,741,823) characters. You can get lot of info about this in SqlServer Books online...


1 Answers

No, they can't. Additionally, they're deprecated in favour of (n)varchar(max) types.

If you need to group them, either change your data structure from (n)text to (n)varchar(max) or do a convert in your group clause

 GROUP BY ProdID, CONVERT(nvarchar(max), ItemDes)
like image 112
podiluska Avatar answered Oct 23 '22 20:10

podiluska