除非使用IS NULL或LIKE运算符,否则无法比较或排序text,ntext和image数据类型。

问题描述:

Use Shoppingkart
select P.ProductSNo,
P.ProductName,
P.ProductDescription,
P.ProductPrice,
P.ProductImage,
P.CategorySNo,
P.CategorySNo,
P.ProductQuantity,
C.CategoryName,
Isnull(Sum(CP.TotalProducts),0) as ProductSold

From Products P
Inner Join Category C
On P.CategorySNo=C.CategorySNo

LEFT Join CustomerProducts CP
On P.ProductSNo=CP.ProductSNo

Group BY
P.ProductSNo,
P.ProductName,
P.ProductDescription,
P.ProductPrice,
P.ProductImage,
P.CategorySNo,

P.ProductQuantity,
C.CategoryName





我收到此错误::





I got This error::

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

正如错误所述,某些数据类型无法比较。在你的陈述中我猜它是 P.ProductImage



一个选项是你首先选择'正常'数据然后使用该结果集并将其与图像数据组合。换句话说,比如



As the error says, some of the data types aren't comparable. In your statement I'd guess it's P.ProductImage.

One option is that you first select the 'normal' data and then use that result set and combine it with the image data. In other words, something like

select a.*,
       (select p.productimage 
        from product p
        where p.productsno = a.productsno) AS ProductImage
from (
      select P.ProductSNo,
      P.ProductName,
      P.ProductDescription,
      P.ProductPrice,
      P.CategorySNo,
      P.CategorySNo,
      P.ProductQuantity,
      C.CategoryName,
      Isnull(Sum(CP.TotalProducts),0) as ProductSold
      From Products P
      Inner Join Category C
      On P.CategorySNo=C.CategorySNo
      LEFT Join CustomerProducts CP
      On P.ProductSNo=CP.ProductSNo
      Group BY
      P.ProductSNo,
      P.ProductName,
      P.ProductDescription,
      P.ProductPrice,
      P.CategorySNo,
      P.ProductQuantity,
      C.CategoryName) a



示例中的连接列可能不正确,但您知道结构更好的数据库:)


The joining column may be incorrect in the example, but you know the structure of the database better :)