select * from GoldCardReplacementData
where 1=1 and len(ReturnDate)>0 or len(ReturnReason)>0
and convert(nvarchar(10),returndate,120)!='1900-01-01'
and convert(nvarchar(10),ReturnDate,120)>='2012-11-01'
and convert(nvarchar(10),ReturnDate,120)<='2012-11-28'
表goldcardreplacementData里面的returndate中的数据有这么几类:“正常的日期”,“1900-01-01”,“null”,我现在想查询,这张表里面的只要returndate为正常的日期都查出来,并且根据提供的日期区间将数据查询出来,现在我这个语句有问题,它把所有的数据都查询出来了,请问,我这个句子要怎么改呢? ------最佳解决方案-------------------- select * from GoldCardReplacementData
where ReturnReason is not null--排除为空的
and convert(nvarchar(10),returndate,120)<>'1900-01-01'--排除你说的那种情况
and ReturnDate between '2012-11-01' and '2012-11-28'--筛选时间范围内的
把你的数据贴出来 ------其他解决方案--------------------
select * from GoldCardReplacementData
where 1=1 and len(ReturnDate)>0 or len(ReturnReason)>0
and convert(nvarchar(10),returndate,120)!='1900-01-01'
and convert(datetime,ReturnDate,120)>='2012-11-01'
and convert(datetime,ReturnDate,120)<='2012-11-28'
select * from GoldCardReplacementData
where 1=1 and ReturnReason is not null
and convert(nvarchar(10),returndate,120)!='1900-01-01'
and ReturnDatebetween '2012-11-01' and '2012-11-28'