我创建了一个过程(使用SQL Server 2008)从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
别忘了CAST()。它让我摆脱了在文本域中查找字符串的麻烦,也就是
SELECT lutUrl WHERE CAST(Url AS varchar) = 'http://www.google.com.au'
对我有帮助的简介是在Mind Chronicles。作者还讨论了排序问题。
按二进制图像数据排序(排序)没有意义。为什么不按其他列排序呢?
修改代码:
-- 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