sql语句 当查询条件为空时不作为条件 怎么写
select * from usertable where name=@name and page=@page
我的要求是当name为空就不作为条件,即:
select * from usertable where page=@page
当page为空不作为条件,即:
select * from usertable where name=@name
当page,name都为空不作为条件,即
select * from usertable
怎么用一条sql语句写出来???
------解决方案--------------------select * from usertable where 1=1 and (name=@name or @name='') and (page=@page or @page='')