数据类型varchar和varbinary(max)在add运算符中不兼容。在尝试创建存储过程时

时间:2017-02-02 08:43:46

标签: sql asp.net sql-server stored-procedures

尝试在sql server中创建存储过程,但我收到此错误。数据类型varchar和varbinary(max)在add运算符中不兼容。

CREATE PROC dbo.SearchAnswers
    @Name varchar(225),
    @Address varchar(225),
    @ServiceRendered varchar(225),
    @spportedHMO varchar(225),
    @States varchar(225),
    @Country varchar(225),
    @OtherServices varchar(225),
    @Hospital_Image varbinary(225)
AS
SELECT *  
FROM Hospital
WHERE Name LIKE '%' + (@Name) + '%'+'' 
    OR Address LIKE ''+'%' + (@Address) + '%'+'' 
    OR ServiceRendered LIKE ''+'%' + (@ServiceRendered) + '%'+'' 
    OR spportedHMO LIKE ''+'%' + (@spportedHMO) + '%'+'' 
    OR States LIKE '' +'%' + (@States) + '%'+'' 
    OR Country LIKE ''+ '%' + (@Country) + '%'+'' 
    OR OtherServices LIKE ''+'%' + (@OtherServices) + '%'+'' 
    OR Hospital_Image LIKE ''+'%' + Cast(@Hospital_Image as varbinary(max)) + '%'

1 个答案:

答案 0 :(得分:1)

您在搜索Hospital_Image时不需要喜欢。将其更改为“=”。如果你需要任何领域,可能会审查;只使用LIKE在字段中搜索包含字符串:

CREATE PROC dbo.SearchAnswers
    @Name varchar(225),
    @Address varchar(225),
    @ServiceRendered varchar(225),
    @spportedHMO varchar(225),
    @States varchar(225),
    @Country varchar(225),
    @OtherServices varchar(225),
    @Hospital_Image varbinary(225)
AS
SELECT *  
FROM Hospital
WHERE Name LIKE '%' + (@Name) + '%'+'' 
    OR Address LIKE ''+'%' + (@Address) + '%'+'' 
    OR ServiceRendered LIKE ''+'%' + (@ServiceRendered) + '%'+'' 
    OR spportedHMO LIKE ''+'%' + (@spportedHMO) + '%'+'' 
    OR States LIKE '' +'%' + (@States) + '%'+'' 
    OR Country LIKE ''+ '%' + (@Country) + '%'+'' 
    OR OtherServices LIKE ''+'%' + (@OtherServices) + '%'+'' 
    OR Hospital_Image = @Hospital_Image