alter procedure sp_test(@productid int) as declare @table table ( id int identity(1,1) not null, productid int not null )insert into @table select 1 insert into @table select 2 insert into @table select 3 insert into @table select 4 insert into @table select 5 insert into @table select 6select * from @table a where productId = (case when @productid != 0 then @productid else null end) union select * from @table where @productid = 0exec sp_test 2直接想到的就这样了大概
as
declare @table table
(
id int identity(1,1) not null,
productid int not null
)insert into @table select 1
insert into @table select 2
insert into @table select 3
insert into @table select 4
insert into @table select 5
insert into @table select 6select *
from @table a
where productId = (case when @productid != 0 then @productid else null end)
union
select *
from @table
where @productid = 0exec sp_test 2直接想到的就这样了大概