SQL adding a number of months onto a date

60 views Asked by At

I have the below SQL code which I am wanting to take the number from the PPD.Month_Diff and add that number (of months) onto a column that is already in date format:

CONVERT(varchar, (DATEADD(MONTH,ED.books_close_date, PPD.Month_Diff)))

However when I run this code I get an error as below

Msg 8116, Level 16, State 1, Line 53 Argument data type datetime is invalid for argument 2 of dateadd function.

I'm not sure if its the conversion part or something else that I'm missing?

1

There are 1 answers

2
Gustav On

Use the correct order of the parameters:

DATEADD(MONTH, PPD.Month_Diff, ED.books_close_date)

DATEADD (Transact-SQL)