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

时间:2011-09-26 17:38:58

标签: sql-server-2008

我创建了一个过程(使用SQL Server 2008)从image表中检索图像数据但这个过程给了我一个错误

  

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

我的程序是:

Create procedure [dbo].[xp_GetImage]
@companyId  udtId
as  
begin

/*=============================================================================
*   Constants
*============================================================================*/
declare 
        @SUCCESS            smallint,
        @FAILED             smallint,
        @ERROR_SEVERITY     smallint,
        @ERROR_STATE1       smallint,
        @theErrorMsg        nvarchar(4000),
        @theErrorState      int,
        @chartCount         int,
        @provider           varchar(128),
        @projectCount       int

select  
        @SUCCESS    =   0,  
        @FAILED     =   -1, 
        @ERROR_SEVERITY = 11,
        @ERROR_STATE1 = 1

begin try

    -- Get the Image

    select  Logo, LogoName,LogoSize
              from CompanyLogo                  
     where CompanyId = @companyId         
  order by Logo desc

end try


begin catch
    set @theErrorMsg = error_message()
    set @theErrorState = error_state()
    raiserror (@theErrorMsg, @ERROR_SEVERITY, @theErrorState)
    return (@FAILED)
end catch
end 
print 'created the procedure xp_GetImage'
go
---end of the procedure
grant EXECUTE on xp_GetImage to public
go

请帮帮我。

2 个答案:

答案 0 :(得分:4)

不要忘记CAST()。它让我摆脱了在文本字段中查找字符串的麻烦,即

SELECT lutUrl WHERE CAST(Url AS varchar) = 'http://www.google.com.au'

帮助我的模糊是Mind Chronicles。作者还讨论了排序问题。

答案 1 :(得分:3)

通过二进制图像数据排序(排序)没有意义。为什么不用其他列排序呢?

示例

修改此代码:

-- Get the Image

  SELECT Logo, LogoName,LogoSize
    FROM CompanyLogo                  
   WHERE CompanyId = @companyId         
ORDER BY Logo desc

对此:

-- Get the Image

  SELECT Logo, LogoName,LogoSize
    FROM CompanyLogo                  
   WHERE CompanyId = @companyId         
ORDER BY LogoName