我已经使用了LIKE
操作一些其它参数搜索卡车位置的存储过程使用与存储过程LIKE操作参数
@location nchar(20),
@time time,
@date date
AS
select
DonationsTruck.VechileId, Phone, Location, [Date], [Time]
from
Vechile, DonationsTruck
where
Vechile.VechileId = DonationsTruck.VechileId
and (((Location like '%'[email protected]+'%') or (Location like '%'[email protected]) or (Location like @location+'%')) or [Date][email protected] or [Time] = @time)
我总是空的其他参数,只能通过位置搜索,但它即使当我使用位置的全名时也不会返回结果
要正确处理您需要明确地检查它,例如NULL值'([Date] = @Date或@Date为NULL)'。顺便说一下,你只需要检查''%'+ @location +'%'',另外两个位置测试是多余的。 – HABO 2013-05-05 03:01:01
[踢坏的习惯:使用旧式JOIN](http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/08/bad-habits-to-kick-using-old-style-joins。 aspx) - 老式*逗号分隔的表*样式列表已停止使用ANSI - ** 92 ** SQL标准(超过** 20年前**) – 2013-05-05 07:15:16