如果我在星期一运行查询,如何获取星期五的日期? [英] How to get date of friday if I am running the query on monday?

查看:84
本文介绍了如果我在星期一运行查询,如何获取星期五的日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT

sdomain.SalesOrg,

sdomain.Id,

sdomain.Phase,

SdoMain。 InitiationDate为CASOrderStartTime

来自

SDOMAIN

WHERE

SdoMain.Status<>'d'

和sdomain.InitiationDate< = Getdate() - 1

和sdomain.Phase in('已提交','OnRoute')



由sdomain.InitiationDate订购



我尝试过:



在上面的查询中,我想得到今天日期之前的一个日期的结果。所以我使用了InitiationDate< = Getdate() - 1。但是星期一我想要采取星期五的日期(假设今天是27个月,17个月,我希望这个查询应该是星期五的日期,即(24日元,17日)。是否有任何功能或任何方式我该怎么办?

请帮助asap /

提前致谢!!!

SELECT
sdomain.SalesOrg ,
sdomain.Id,
sdomain.Phase,
SdoMain.InitiationDate as "CASOrderStartTime"
From
SDOMAIN
WHERE
SdoMain.Status<>'d'
and sdomain.InitiationDate<=Getdate()-1
and sdomain.Phase in ('Submitted','OnRoute')

order by sdomain.InitiationDate

What I have tried:

In the above query,I want to get the result of one date prior of the today's date.So I have used InitiationDate<=Getdate()-1 .But on monday i want to take the friday's date (suppose today is 27 feb,17 i.e.monday and I want that this query should take the friday's date i.e.(24 feb,17).Is there any function or any way how can I do this??
Please help asap/
Thanks in advance!!!

推荐答案

试试这个:
declare @date datetime;
select @date =
case
   when datepart(weekday, getdate()) = 2 then getdate()-3
   else getdate() - 1
end;
select @date

DATEPART(Transact-SQL) [ ^ ]


Quote:

如果我在星期一运行查询,如何获取星期五的日期?

How to get date of friday if I am running the query on monday?



我不明白你的问题。

你已经知道怎么去前一天了, Getdate() - 1 ,又来自今天的27,你检查了26。

你想知道今天27,你检查24,你不能数到3并获得 Getdate() -3


I don't understand your problem.
You already know how to go to previous day, with Getdate()-1, aka from today the 27, you check the 26.
And you wonder from today the 27, you check the 24, are you unable to count to 3 and get Getdate()-3 ?


这篇关于如果我在星期一运行查询,如何获取星期五的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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