大哥们:
我有一个sql语句不会写。要求是这样的:在”电影名称“中查找,用户输入的关键,如果有模糊相匹配的就全部显示出来。
比如查找”电影名称“字段中,凡是”上海“的电影记录,怎么写?我写了一个但执行时,没什么反映,鼓计存储过程写错了。select count(id) from Film_Info where FilmName like "%@SearchChar %" and FilmClass=@FilmClass2@SearchChar是用户输入的关键字,参数
这是统计 相匹配的电影记录的个数。但执行就是没反映。等于没有执行一下,请大家帮我看看有错吗??
我有一个sql语句不会写。要求是这样的:在”电影名称“中查找,用户输入的关键,如果有模糊相匹配的就全部显示出来。
比如查找”电影名称“字段中,凡是”上海“的电影记录,怎么写?我写了一个但执行时,没什么反映,鼓计存储过程写错了。select count(id) from Film_Info where FilmName like "%@SearchChar %" and FilmClass=@FilmClass2@SearchChar是用户输入的关键字,参数
这是统计 相匹配的电影记录的个数。但执行就是没反映。等于没有执行一下,请大家帮我看看有错吗??
你这句语句大概功能是:查找所有(电影)文件名中包函SearchChar内容的文件个数。对吧?
------------------------------------------------------------------正式,查找电影,并列出CREATE procedure SearchFilm
(
@pagesize int,
@pageindex int,
@docount bit,
@FilmClass2 char(10),
@SearchChar char(30)
)
as
set nocount on
if(@docount=1)
select count(id) from Film_Info where FilmName like '%"+@SearchChar+"%' and FilmClass=@FilmClass2
else
begin
declare @indextable table(id int identity(1,1),nid int)
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
set rowcount @PageUpperBound
insert into @indextable(nid) select id from Film_Info order by ID desc
select * from Film_Info O,@indextable t where O.id=t.nid
and t.id>@PageLowerBound and t.id<=@PageUpperBound and FilmName like '%"+@SearchChar+"%' and FilmClass=@FilmClass2 order by t.id
end
set nocount off
GO
我赞同
http://dev.csdn.net/develop/article/69/69396.shtm
但问题是:如何 用@SearchChar 来代替 这个 '少林',要是@SearchChar 写到
select count(id) from Film_Info where FilmName like '%'+'少林'+'%' and FilmClass=@FilmClass2 中,我不会写了
给 @SearchChar 传参数的时候,手动给参数 加上 % 号,注意不要 ' 号。
楼主你认真看了没啊