Hi,
I can't get the following to work:
I try to update all dates in a table by adding one year.
The SQL statement I need for this is of course quite simple:
UPDATE TableA SET [endDate] = DATEADD(yy, 1, endDate)
When I want to do this in code however, it all starts to get complicated.
I have written the following code:
DbFunctionCall dbFunctionCall = new DbFunctionCall("DATEADD", new object[] {"yy", 1, TableAFields.EndDate });
TableAEntity newValues = new TableAEntity();
newValues.Fields[(int)TableAFieldIndex.EndDate].ExpressionToApply = dbFunctionCall;
TableACollection updater = new TableACollection();
updater.UpdateMulti(newValues, null);
I then get the following SQL statement:
exec sp_executesql N'UPDATE TableA SET [EndDate]=DATEADD(@LOce01b7d71, @LO12, [EndDate]),N'@LOce01b7d71 nvarchar(2),@LO12 int',@LOce01b7d71=N'yy',@LO12=1
This fails with the following error: Invalid parameter 1 specified for dateadd
The problem is that DATEADD does not accept the yy datepart in such a fashion.
How can I resolve this? Note that in the final code, the datepart must be variabel.
Regards,
Patrick