Rash
Rash

Reputation: 896

I am getting error while using Group By clause

I have written the following query for group by clause

SELECT  OrderDetails.Quantity,
        OrderDetails.options 
FROM    OrderDetails  
Group by OrderDetails.Quantity,
        OrderDetails.options 
Order by OrderDetails.options DESC

OrderDetails.options this column is of datatype nvarchar(255) and quantity is float.

But I am getting error like this:

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

I am new to SQL can any one please help me out

Thanks in advance!

Upvotes: 0

Views: 115

Answers (2)

otaku
otaku

Reputation: 964

Double check to make sure that the columns does not have the datatype TEXT or NText. If there is a column that has the datatype Text or NText then you can convert them to use NVARCHAR(MAX).

Upvotes: 4

Mahesh Sambu
Mahesh Sambu

Reputation: 349

Group by should have an aggregate operator so u might need to sum up the order quantity to get it done. Try this out :

  SELECT  sum(OrderDetails.Quantity),OrderDetails.options 
  FROM    OrderDetails  
  Group by  OrderDetails.options 
  Order by OrderDetails.options DESC

Upvotes: 1

Related Questions