ITPub博客

首页 > > > sql全站搜索出来的结果 怎么跳到相应的页面呢?怎么样的代码搜索效率最高呢?

sql全站搜索出来的结果 怎么跳到相应的页面呢?怎么样的代码搜索效率最高呢?

作者:lilyone 时间:2019-10-11 16:15:53 0 删除 编辑

给看看我这代码。。。怎么把搜索出来的结果。跳转到相应页面呢?  我这是一个比较大的网站,里面要一个全站搜索功能~

create proc Full_Search(@string varchar(50))

as

begin

declare @tbname varchar(50)

declare tbroy cursor  for select name from sysobjects

where xtype='u'   --第一个游标遍历所有的表

open tbroy

fetch next from tbroy into @tbname

while @@fetch_status=0

begin

declare @colname varchar(50)

declare colroy cursor for select name from syscolumns

where id=object_id(@tbname) and xtype in (

select xtype from systypes

where name in ('varchar','nvarchar','char','nchar') --数据类型为字符型的字段

) --第二个游标是第一个游标的嵌套游标,遍历某个表的所有字段

open colroy

fetch next from colroy into @colname

while @@fetch_status=0

begin

declare @sql nvarchar(1000),@j int

select @sql='select @i=count(1) from '+@tbname+'  where '+ @colname+' like'+'''%'+@string+'%'''

exec sp_executesql @sql,N'@i int output',@i=@j output   --输出满足条件表的记录数

if @j>0

exec('select  distinct'+@colname+'from '+@tbname+'  where '+ @colname+' like'+'''%'+@string+'%''')

fetch next from colroy into @colname

end

close colroy

deallocate colroy

fetch next from tbroy into @tbname

end

close tbroy

deallocate tbroy

end

exec Full_Search  '一'

drop proc Full_Search

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4635/viewspace-3155587/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-01

  • 博文量
    159
  • 访问量
    974