27,579
社区成员
发帖
与我相关
我的任务
分享
--参考:
DECLARE @var INT
SET @var = 1
select *
from A
WHERE 1 = 1
AND (@var = 0 OR code LIKE '%') --当然,这一行可以不要^^,like '%'相当于1=1
AND (@var = 1 OR code not like '七%')
create procedure getA
(@flg int)
as
begin
if @flg=1
select * from A
else
select * from A where code not like '七%'
end
go
--执行
exec getA 0
create function f_name(@num int)
returns table @tb()--A表字段
begin
if @num=1
insert into @tb select * from A where code like '%'
else
insert into @tb select * from A where code not like '七%'
return
end
select * from dbo.f_name