SQL 如何将列中的天添加到 DB2 中的当前日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8210697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:21:14  来源:igfitidea点击:

How to add Days from a column to a current Date in DB2?

sqldb2

提问by Njax3SmmM2x2a0Zf7Hpd

I am writing this sql to dynamically calculate certain number of days as below. But I don't know how to make it work because I keep getting the error.

我正在编写这个 sql 来动态计算特定的天数,如下所示。但我不知道如何使它工作,因为我不断收到错误消息。

select Current Date + ( Dynamic numbr of days calculation here ) from  TableName

Usually all the guides shows examples as Current Date + 1 Day (this works but not the above) Any ideas how can I get it to work from ?

通常所有指南都将示例显示为当前日期 + 1 天(这有效,但不是上述)任何想法如何让它工作?

回答by kedar kamthe

select Current Date + Dynamic numbrDAYS FROM TableName

选择当前日期 +动态 numbrDAYS FROM TableName

e.g.

例如

select Current Date + 15 DAYS  from TableName

here 15 is dynamic number.

这里 15 是动态数字。

回答by Gokul

SELECT CURRENT_DATE + (your dynamic numeric field) DAYS FROM FILE_NAME

Example based on AS400:

基于 AS400 的示例:

1)

1)

SELECT CURDATE() + (FLDA) DAYS FROM FILEA

2)

2)

SELECT CURDATE() + 8 DAYS FROM FILEA

回答by Shamil Kattungal

Try this

尝试这个

 SELECT                                            
 DATE(DTE_BILL_EFFCTV - 301 DAYS)                  
 FROM BILL_ACCT                 
 WHERE                                             
 DTE_BILL_EFFCTV > DATE(CURRENT DATE - 300 DAYS) ;