选择具有日期功能的陈述 [英] select statment with date function

查看:62
本文介绍了选择具有日期功能的陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我想构建一个sql select语句,在其中我可以获取今天之前的日期,这意味着今天是2012年6月20日,我必须获取日期为2012年6月19日.但是与此同时,我也想获取其他列,请帮助我使用此代码.

请帮忙
谢谢

Hello

I want to build a sql select statment in which i can get the date before today that means today is 20 june 2012, i have to get the date as 19 june 2012. But with this i want to get other columns as well please help me with this code.

Please help
Thanks

推荐答案

SELECT GetDate()-1 AS Yesterday, Field2, Field3
FROM table1


这里是一个,请尝试一下

Here is one, please give it a try

Select dateadd(d,-1,GETDATE()) 



问候
塞巴斯蒂安(Sebastian)



Regards
Sebastian


例如:
MyTable:
ID    ... BigInt
Title ... NvarChar(50)
Date  ... DateTime



查询:



Query:

Select  ID,
        Title,
        (select [Date]
            Where [Date]>='2012-06-20') as Date
from MyTable


这篇关于选择具有日期功能的陈述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆