码迷,mamicode.com
首页 > 数据库 > 详细

sql 存储过程带有模糊查询条件

时间:2017-12-23 12:05:25      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:into   like   ddr   esc   count   begin   res   varchar   doc   

一个简单的存储过程:

Create procedure [dbo].[Proc_SeachJob] 
(@startRecordIndex int,
@endRecordIndex int,
@seach nvarchar(10),
@docount bit)
as
set nocount on
if(@docount=1)
--只需要把%与搜索的字符串用拼接的方式即可
select count(*) from Job where name like %@seach% or work_address like %@seach%
else
begin
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endRecordIndex
insert into @indextable(nid) select ID from Job  where name like %@seach% or work_address like %@seach% order by CreateTime desc
select * from Job O,@indextable t where O.ID=t.nid
and t.id between @startRecordIndex and @endRecordIndex order by t.id
end
set nocount off

 

sql 存储过程带有模糊查询条件

标签:into   like   ddr   esc   count   begin   res   varchar   doc   

原文地址:http://www.cnblogs.com/xinqi1995/p/8092636.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!