set @sql= ' select * from table where 1=1 '
|
if (@addDate is not null )
|
set @sql = @sql+ ' and addDate = ' + @addDate + ' ' |
if (@ name <> '' and is not null )
|
set @sql = @sql+ ' and name = ' + @ name + ' '
|
if (@addDate is not null ) and (@ name <> '' )
|
select * from table where addDate = @addDate and name = @ name |
else if (@addDate is not null ) and (@ name = '' )
|
select * from table where addDate = @addDate
|
else if(@addDate is null ) and (@ name <> '' )
|
select * from table where and name = @ name |
else if(@addDate is null ) and (@ name = '' )
|
select * from table where (addDate = @addDate or @addDate is null ) and ( name = @ name or @ name = '' )
|
SELECT * FROM table where |
addDate = CASE @addDate IS NULL THEN addDate ELSE @addDate END ,
|
name = CASE @ name WHEN '' THEN name ELSE @ name END
|
地址:http://www.cnblogs.com/xiaofengfeng/archive/2010/11/09/1873106.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。