2011-09-26 31 views
2

我創建了一個過程(使用SQL Server 2008)從image表中檢索圖像數據,但此過程給了我一個錯誤無法比較或排序文本,ntext和圖像數據類型,除非使用IS NULL或LIKE運算符

「使用時除外的文本,ntext和圖像數據類型不能比較或排序, 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 

請幫助我。

+1

另外:*將在未來版本的Microsoft SQL Server中刪除ntext,文本和圖像數據類型。 **避免在新開發工作中使用這些數據類型**,並計劃修改當前使用它們的應用程序。請使用nvarchar(max),varchar(max)和varbinary(max)代替。* [請參閱MSDN文檔以獲取更多信息](http://msdn.microsoft.com/zh-cn/library/ms187993.aspx) –

+0

排序依據一個字節數組,爲什麼? – Magnus

回答

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 
4

不要忘了CAST()。它只是讓我出去尋找在文本字段中輸入字符串的麻煩,即

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

,幫助我在Mind Chronicles Blurb的。作者還討論了排序問題。

相關問題