sql 存儲過程帶有模糊查詢條件


一個簡單的存儲過程:

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM