尝试在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)) + '%'
答案 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