日期:2014-05-18  浏览次数:20418 次

求SQL语句一条.....(在线等)
数据库格式如下:
ID title(varchar 100)
1 中共中央
2 2004-8-5
3 中国人民
4 2005-9-8
5 2005-8-5

要求:显示数据库title小于2005-8-6(title不包括非日期型)






------解决方案--------------------
SQL code
create table T(ID int, title varchar(100) )

insert into t select 1, '中共中央 '
insert into t select 2, '2004-8-5'
insert into t select 3, '中国人民'
insert into t select 4, '2005-9-8'
insert into t select 5, '2005-8-5'

--要求:显示数据库title小于2005-8-6(title不包括非日期型) 


select *
from t
where isdate(title)=1 and title<'2005-08-06'

drop table T

------解决方案--------------------
select * from
(select * from [table] where isdate(title)=1)aa
where datediff(day,title,'2005-8-6')>0
------解决方案--------------------
select *
from t
where isdate(title)=1 and title<'2005-08-06'

这个不错,,,
------解决方案--------------------
create table Layto(ID int, title varchar(100) )

insert into Layto select 1, '中共中央 '
insert into Layto select 2, '2004-8-5'
insert into Layto select 3, '中国人民'
insert into Layto select 4, '2005-9-8'
insert into Layto select 5, '2005-8-5'

select * from Layto

select * from Layto where isdate(title) = 1 and title<'2005-8-6'
-------------------------
ID title
2 2004-8-5
5 2005-8-5

------解决方案--------------------
数据库格式如下: 
ID title(varchar 100) 
1 中共中央 
2 2004-8-5 
3 中国人民 
4 2005-9-8 
5 2005-8-5 

要求:显示数据库title小于2005-8-6(title不包括非日期型) 

----------------------

select * from tb where isdate(title) = 1 and cast(title as date) < '2005-08-06'