注册 登录
编程论坛 ASP.NET技术论坛

[求助]时间比较的问题

ice_beiyu 发布于 2007-07-27 08:32, 529 次点击
在数据库查询语句中进行时间比较,判断数据库中的时间与当前时间差是不是小于两年。哪位高手有好的方法请指教!
4 回复
#2
jyoseyi2007-07-27 09:12
select @@ROWCOUNT select * from [user] where( year( getdate()) - year(birthday) >2)
--student 表名
--birthday 生日 时间

--查询出来的结果是,与当前时间差小于两年的行数

--判断查询出来的结果是不是大于0 就可以知道是不是小于2年了
#3
jyoseyi2007-07-27 09:15
select @@ROWCOUNT select * from [user] where( year( getdate()) - year(birthday) <2)

#4
ice_beiyu2007-07-27 09:24
搞定,谢谢!
#5
hinroe2007-07-27 13:40

我想问一下,select @@ROWCOUNT select * from [user] where( year( getdate()) - year(birthday) <2)
语句可以这样写吗?那如果我要向一个表中插入(新建)一行记录,又要同时从其中提取id,那是不是就可以写成 select CategoryID INSERT INTO MediaCategories(Name1, Remark, [Level], ParentID)
VALUES (@Name1,@Remark,@Level,@ParentID)

1