问题
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