SQL 语句中日期格式转换的问题,求教~

wangl8809 2015-05-01 04:00:45
update Inventory set dModifyDate=GETDATE() where cInvCode in (select cinvcode from rdrecords08 where id in (select id from RdRecord08 where dDate='2015-04-30 00:00:00.000'))


我想在SQL里面设置一个计划任务,每天定时执行这个SQL语句,语句最后那个ddate的 值我想取当前系统日期(格式是:2015-04-30 00:00:00.000),想问下怎么在这个语句里把取到的日期自动转换成语句里的那个格式?
用getdate() 取到的日期格式好像不是这种格式~
请高手指教~~感谢~
...全文
201 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
l1314j 2015-06-11
  • 打赏
  • 举报
回复
如果是取数据字段来与当前时间比较 那你可以有多种方法


update Inventory set dModifyDate=GETDATE() where cInvCode in (select cinvcode from rdrecords08 where  id in  (select id from RdRecord08 where convert(varchar(10),dDate,120)=convert(varchar(10),getdate(),120)) 
或者用日期做比较 datediff 你需要的实现效果,用下面这种方法比较很比较好

update Inventory set dModifyDate=GETDATE() where cInvCode in (select cinvcode from rdrecords08 where  id in  
(select id from RdRecord08 where 
DATEDIFF(DAY,dDate,GETDATE())=0
l1314j 2015-06-11
  • 打赏
  • 举报
回复

update Inventory set dModifyDate=GETDATE() where cInvCode in (select cinvcode from rdrecords08 where  id in  (select id from RdRecord08 where dDate=convert(varchar(10),getdate(),120)) 

楼上的方法都可以
shinger126 2015-06-11
  • 打赏
  • 举报
回复
dDate='2015-04-30 00:00:00.000' 修改成dDate=cast(CONVERT(varchar(10),getdate(),121) as datetime)
习惯性蹭分 2015-06-10
  • 打赏
  • 举报
回复

select dateadd(day,datediff(day,0,getdate()),0),convert(varchar(40),dateadd(day,datediff(day,0,getdate()),0),120)

江南雪_158 2015-06-10
  • 打赏
  • 举报
回复
时间格式都可以通过convert函数进行转换的,可以通过限制第三个参数控制不同的格式
tcmakebest 2015-05-02
  • 打赏
  • 举报
回复
楼主难道不明白数据类型是怎么回事. getdate()是日期类型,不存在格式的问题,只有将它转成字符串的时候才会有格式的概念. 如果 dDate 是字符类型, 比较的时候那得是完全相等的,用这个
select convert(varchar(10),getdate(),120) + ' 00:00:00.000'
如果 dDate 是日期类型, 用上面的或者下面的都可以
select convert(varchar(10),getdate(),120)

22,206

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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