在網上看到乙個sql server的多條件查詢,感覺很精練,並結合實際的專案,做了乙個帶分頁的儲存過程
create procedure [sgetrtableheadp_mc]
--獲取簡歷數目並建立臨時表分頁,帶多條件引數查詢
@status varchar(50),
@city varchar(100),
--高階查詢條件
@st varchar(50),
@et varchar(50),
@idnumber varchar(50),
@name varchar(50),
@major varchar(200),
@school varchar(200),
@majortype varchar(200),
@degree varchar(50),
@job1 varchar(200),
@job2 varchar(200),
--page
@pagesize int, -- 一頁顯示的記錄數
@pageindex int ,-- 當前頁碼(從1開始)
@pagecount int output,--總頁數
@rc int output --總記錄數
asdeclare @strsql varchar(1000)
--生成臨時表
select identity(int,1,1) as id,idnumber , name as 姓名,school as 畢業院校,major as 專業,degree as 學歷,job1 as 申請職位一,job2 as 申請職位二,mob as 手機
into #tmp from stu_basicinfo where id in (select bid from resume_status where status=@status)
and interviewaddr=@city
and (submittime between @st and @et or (@st='' and @et=''))
and (idnumber=@idnumber or @idnumber='')
and (name like @name or @name='')
and (major like @major or @major='')
and (majortype=@majortype or @majortype='')
and (school like @school or @school='')
and (degree=@degree or @degree='')
and (job1=@job1 or @job1='')
and (job2=@job2 or @job2='')
--查詢總記錄數
select @rc=count(*) from #tmp
--計算頁數
if(@rc%@pagesize=0)
begin
select @pagecount=@rc/@pagesize
endelse
if(@rc%@pagesize<>0)
begin
select @pagecount=@rc/@pagesize+1
end--page主查詢語句
if(@pageindex=1)
begin
set @strsql = 'select top ' + str(@pagesize) + '* from #tmp order by id'
endelse
if(@pageindex>1)
begin
set @strsql = 'select top ' + str(@pagesize) + '* from #tmp where id>(select max(id) from (select top ' + str(@pagesize*(@pageindex-1)) + ' id from #tmp order by id) as t) order by id'
endexec(@strsql)
--drop table #tmp
go
Mybatis 多條件動態查詢
例 簡單的乙個查詢 select from student tbl st where st.student name like concat concat 但是此時如果studentname是null或空字串,此語句很可能報錯或查詢結果為空。此時我們使用if動態sql語句先進行判斷,如果值為null...
多條件動態LINQ 組合查詢
本文章 參考 以往我們都是通過判斷的方式來拼接查詢的sql字串,但是現在我們面對是強型別的linq查詢,是否可以很方便的進行類似查詢。eg string userid string.empty userid e351d301 f64b 412c b9ef 573f41235af2 string us...
多條件查詢
思路 1.獲取引數值 2.生成查詢條件 3.獲取查詢結果 4.繫結查詢選項 呼叫geturlhtml方法生成查詢url 例如 var y2013 pnvshihufu qbeijing sxuhuiqu 得到url變數值 protected string geturlval string name ...