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

旧巷老猫 提交于 2019-12-22 04:09:34

问题


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.

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:


select Current Date + Dynamic numbr DAYS FROM TableName

e.g.

select Current Date + 15 DAYS  from TableName

here 15 is dynamic number.




回答2:


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

Example based on AS400:

1)

SELECT CURDATE() + (FLDA) DAYS FROM FILEA

2)

SELECT CURDATE() + 8 DAYS FROM FILEA



回答3:


Try this

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


来源:https://stackoverflow.com/questions/8210697/how-to-add-days-from-a-column-to-a-current-date-in-db2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!