Text, ntext, and image data types can not be compared or sorted except when using the IS NULL or LIKE operator

advertisements

I created a procedure (using SQL Server 2008) to retrieve the image data from image table but this procedures giving me an error

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

My procedure is this:

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

please help me.


Don't forget about CAST(). It just got me out of trouble looking for a string in a text field, viz

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

The blurb that helped me is at Mind Chronicles. The author discusses the sorting issue as well.