日期:2014-05-17 浏览次数:20730 次
SELECT ContractName FROM dbo.ContractExecution WHERE ContractBeginTime < CASE WHEN ContractEndTime = '' THEN '2013-10-1 ' ELSE '2013-10-1 ' END AND ContractEndTime > CASE WHEN ContractEndTime = '' THEN 0 ELSE '2012-10-1' END ORDER BY ID DESC
------解决方案--------------------
1.select ContractName from ContractExecution where ContractBeginTime <'2013-10-1 ' and ContractEndTime>case when ContractEndTime='' then '1900-1-1' else '2012-10-1' end
2.if ContractEndTime=''
select ContractName from dbo.ContractExecution where ContractBeginTime <'2013-10-1 '
else
select ContractName from ContractExecution where ContractBeginTime <'2013-10-1 ' and ContractEndTime>'2012-10-1'
以上两种方法都可以实现楼主想要的。