请问各位高手:这个sql语句该怎么写????

shanxia 2003-12-17 11:26:58
我有个表A21,里面有字段“comlete”和“Indate”,假如我取了当天的日期ThisTime,我该怎么取出comlete为0和ThisTime比Indate大两天的数据呢?主要是ThisTime和Indate怎么比较出大两天?
谢谢各位大虾了,搞了很久效果都不是很好!
请各位帮帮忙!
谢谢~~~~~~~~~~
...全文
103 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
shanxia 2003-12-17
  • 打赏
  • 举报
回复
如果我要判断比数据库里多一分钟怎么判断呢?
因为调试的时候我肯定不能等两天啊
如果一分钟成功的话肯定两天也行了
shanxia 2003-12-17
  • 打赏
  • 举报
回复
谢谢各位的指点,如果我查出了一些值,再用这些值去查另外一个表Sys_User里的phone和name字段请问可以和上面的嵌套在一起查询吗?还是必须得先查出上面的值然后再用一个sql语句继续查?
zjcxc 元老 2003-12-17
  • 打赏
  • 举报
回复

declare @thistime datetime
set @thistime=getdate()
select * from A21
where comlete=0 and datediff(day,indate,@thistime)>2
victorycyz 2003-12-17
  • 打赏
  • 举报
回复
select *
from A21
where comlete = 0 and datediff(day,indate,getdate()) = 2
shanxia 2003-12-17
  • 打赏
  • 举报
回复
没有用到ThisTime?我是想这样:假如有封邮件是今天发的,日期存在Indate里,然后每天判断Indate是否超过两天没看,如果超过两天就提示用户,否则就不理会,还有,可以写一个触发器用在这里每天判断吗?不然的话如果用户没用软件,就取不出当天的日期到数据库中去判断啊,我该怎么做呢?
realgz 2003-12-17
  • 打赏
  • 举报
回复
select * from table where =0 and convert(varchar(8),Indate,112)=(convert(varchar(8),ThisTime-2,112))
txlicenhe 2003-12-17
  • 打赏
  • 举报
回复
select * from A21
where complete = '0'
and datediff(day,indate,getdate()) > 2 -- 两天前
-- and datediff(day,getdate(),indate) > 2 -- 两天后
zjcxc 元老 2003-12-17
  • 打赏
  • 举报
回复
转版吧.
没用过java
shanxia 2003-12-17
  • 打赏
  • 举报
回复
上面各位的怎么判断不到呢?
ThisTime是java里面得到的一个变量啊,并不是表里的字段来得

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧