简体   繁体   中英

DateAdd - SQL expression

I am trying to create an expression with SQL. The expression value is trying to assign a value to the days of the week. Sunday is 1 through to Saturday which is 7. I am then trying to add 5 days if it is a Monday so that it lands on a Friday otherwise every other day add 7 days. Eg

WeekDay Inlist("2",",") DateAdd(5, "d") OR ds WeekDay Inlist("1,3,4,5,6,7",",") DateAdd(7, "d")

However this does not seem to work? So basically I enter my date in a databox as 15/03/2017 which is a Wednesday, Our expression would say if its a Monday to add 5 days and therefore result in false. Because its a Wednesday we would need to say add 7 days, this ignores Saturday and Sunday and therefore would result in True. This would land on the following Wednesday.

Any ideas? :D

Not sure which variation of SQL you're using, but there's likely an equivalent to the T-SQL CHOOSE() and DATEPART() functions in most variants that will do this.

The expression syntax could end up something like this:

DATEADD(CHOOSE(DATEPART("dw", date), 7, 5, 7, 7, 7, 7, 7), "d", date)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM