動態(tài)執(zhí)行存儲過程條件處理
來源:懂視網(wǎng)
責編:小采
時間:2020-11-09 10:02:13
動態(tài)執(zhí)行存儲過程條件處理
動態(tài)執(zhí)行存儲過程條件處理:動態(tài)執(zhí)行條件處理 create procedure test(@where1 nvarchar(2000)) as declare @sql nvarchar(2000) set @sql= 'select * from tabletest where 1=1 '+ @where1 exec (@sql) exec test 'and wher
導讀動態(tài)執(zhí)行存儲過程條件處理:動態(tài)執(zhí)行條件處理 create procedure test(@where1 nvarchar(2000)) as declare @sql nvarchar(2000) set @sql= 'select * from tabletest where 1=1 '+ @where1 exec (@sql) exec test 'and wher

//
create procedure test(@where1 int, @where2 int, @where3 int)
as
if @where1 is not null and @where2 is null and @where3 is null
select * from tabletest where where1 = @where1
if @where1 is not null and @where2 is not null and @where3 is null
select * from tabletest where where1 = @where1 and where2 = @where2
if @where1 is not null and @where2 is not null and @where3 is not null
select * from tabletest where where1 = @where1 and where2 = @where2 and where3 = @where3
//
select *
from tabletest
where (where1 = @where1 or @where1 is null)
and (where2 = @where2 or @where2 is null)
and (where3 = @where3 or @where3 is null);
//
select *
from tabletest
where where1 = case when @where1 is not null then @where1 else where1 end and
where2 = case when @where2 is not null then @where2 else where2 end and
where3 = case when @where3 is not null then @where3 else where3 end
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
動態(tài)執(zhí)行存儲過程條件處理
動態(tài)執(zhí)行存儲過程條件處理:動態(tài)執(zhí)行條件處理 create procedure test(@where1 nvarchar(2000)) as declare @sql nvarchar(2000) set @sql= 'select * from tabletest where 1=1 '+ @where1 exec (@sql) exec test 'and wher