1
select
*
from
article
2 where
3 (title like ' %@title% ' or @title = '' )
4 and
5 (man = @man or @man = '' )
6 and
7 ( datediff ( day ,djtime,getdate()) < @zjsj or @zjsj != 0 )
8 and
9 (depart = @depart or @depart = '' )
解释一下模糊查询标题,对应作者,距离@zjsj以内的所有文章,还有对应部门,每一个都可以缺省,比一个一个得去判断简单多了,
2 where
3 (title like ' %@title% ' or @title = '' )
4 and
5 (man = @man or @man = '' )
6 and
7 ( datediff ( day ,djtime,getdate()) < @zjsj or @zjsj != 0 )
8 and
9 (depart = @depart or @depart = '' )
还有一个就是有可能是null值的,那我们就用 is null来判断就可以了,原理都是一样的!
共勉!