select * from Article where Article_id= case when @article_id=0 then Article_id else @article_id end
drop table Article create table Article ( Article_id int identity(1,1) primary key ,name varchar(10)) insert into Article select 'AA' union all select 'BB' union all select 'CC' union all select 'DD' declare @article_id int set @article_id = 2select * from Article where ','+cast(Article_id as varchar)+',' like '%'+ case when @article_id = 0 then '' else ','+cast(@article_id as varchar)+',' end +'%'=============== 2 BB
declare @article_id int set @article_id = 0 select * from Article where Article_id = ( case when @Article_id = 0 then Article_id else @article_id end)
select * from Article where Article_id= (case when @article_id=0 then Article_id else @article_id end)
这方法真不错。
CREATE PROC ARTICLEPRO(@article_id VARCHAR(8000)) AS BEGIN IF(@article_id=0) BEGIN select * from Article ELSE select * from Article where Article_id=@article_id END END (
select * from Article where Article_id=isnull(nullif(@article_id,0),article_id)
from Article
where
Article_id= case when @article_id=0
then Article_id
else @article_id
end
drop table Article
create table Article ( Article_id int identity(1,1) primary key ,name varchar(10))
insert into Article
select 'AA' union all
select 'BB' union all
select 'CC' union all
select 'DD' declare @article_id int
set @article_id = 2select * from Article where ','+cast(Article_id as varchar)+','
like '%'+ case when @article_id = 0 then '' else ','+cast(@article_id as varchar)+',' end +'%'===============
2 BB
declare @article_id int
set @article_id = 0
select * from Article
where Article_id = ( case when @Article_id = 0 then Article_id else @article_id end)
from Article
where Article_id= (case when @article_id=0 then Article_id
else @article_id end)
这方法真不错。
CREATE PROC ARTICLEPRO(@article_id VARCHAR(8000))
AS
BEGIN
IF(@article_id=0)
BEGIN
select * from Article
ELSE
select * from Article where Article_id=@article_id
END
END
(
select * from Article where Article_id=isnull(nullif(@article_id,0),article_id)