一个简单的查询问题。 查询 AAA里,非空非null,日期为2003-07-01之后的数据。(包括2003-07-01,2004-01-05也算)字段里 可能有些为非标准的日期数据 如 2003-7-1 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select * from aaa where datediff(d,'2003-07-01',getdate())>0 select * from tb where isnull(字段,'')<>'' and 字段<dateadd(dd,1,'2003-07-01') select * from aaa where datediff(d,'2003-07-01',getdate())>= 0 select * from aaa where datediff(d,'2003-07-01',getdate())>= 0 declare @tb table (dt datetime)insert into @tb select nullinsert into @tb select ''insert into @tb select '2003-07-01'insert into @tb select '2004-01-05'select * from @tb where dt>='2003-07-01'2003-07-01 00:00:00.0002004-01-05 00:00:00.000直接写就行,上面以为小于了 服务器: 消息 241,级别 16,状态 1,行 1从字符串转换为 datetime 时发生语法错误。 select * from aaa where datediff(d,col,getdate())>= 0 and isdate(col)=1 SELECT * FROM AAAWHERE 字段名 is not null and convert(varchar(10),日期,120) SELECT * FROM AAA WHERE 字段名 is not null and convert(varchar(10),日期,120) >='2003-07-01' 不知这些可是楼主要的结果。我的分析是不是楼主AAA字段里有些不是日期型的数据,想要把他转换为日期型?如是这样可以用CAST(AAA AS DATETIME)转换. 星辰技术社区:www.netcsharp.cn,我们将帮您以最快的速度找到最佳的解决方案 需要一个相减的SQL 基础问题 SQL2005企业管理器不能正常的保留登录密码. 求一个SQL语句,谢谢了! 如何循环字段并计算 求一段存储过程 用C++ 向数据库插入10万条语句循环 高分求购建表存储过程!! set nocout on什么意思啊? 关于创建临时表问题? bcp格式文件未知版本 查询指定范围的所有内容!!(请教高手帮忙)
where isnull(字段,'')<>'' and 字段<dateadd(dd,1,'2003-07-01')
from aaa
where datediff(d,'2003-07-01',getdate())>= 0
from aaa
where datediff(d,'2003-07-01',getdate())>= 0
insert into @tb select null
insert into @tb select ''
insert into @tb select '2003-07-01'
insert into @tb select '2004-01-05'select * from @tb
where dt>='2003-07-01'2003-07-01 00:00:00.000
2004-01-05 00:00:00.000直接写就行,上面以为小于了
从字符串转换为 datetime 时发生语法错误。
from aaa
where datediff(d,col,getdate())>= 0 and isdate(col)=1
FROM AAA
WHERE 字段名 is not null
and convert(varchar(10),日期,120)
FROM AAA
WHERE 字段名 is not null
and convert(varchar(10),日期,120) >='2003-07-01'
我的分析是不是楼主AAA字段里有些不是日期型的数据,想要把他转换为日期型?
如是这样可以用CAST(AAA AS DATETIME)转换.