sp0987 0 Posted March 5 Hi, We are using Db express components in our Delphi 11 IDE to connect to Database. We are getting Argument Out of Range exception under the following scenario 1. Note: dys parameter has an prefix of '-' to subtract the days from getdate(); In Scenario 1 , we are getting the exception "ArgumentOutOfRange. In Scenario 2 , we gave a space between the '-' operator and the dys parameter. In this case we didn't get any exception. Scenario 1: q.SQL.Add('DECLARE @MinEffDate date = DATEADD(DAY, -:dys, getdate())'); q.SQL.Add('DECLARE @MinRefDate date = :dt'); q.SQL.Add( 'select CONVERT(varchar(10), @MinEffDate, 101) AS MinEffDate,CONVERT(varchar(10), @MinRefDate, 101) AS MinRefDate'); q.ParamByName('dys').AsInteger := 30; q.ParamByName('dt').AsDateTime := StrToDateTimedef('2018-11-01 00:00:00', 2); Scenario 2: q.SQL.Add('DECLARE @MinEffDate date = DATEADD(DAY, - :dys, getdate())'); q.SQL.Add('DECLARE @MinRefDate date = :dt'); q.SQL.Add( 'select CONVERT(varchar(10), @MinEffDate, 101) AS MinEffDate,CONVERT(varchar(10), @MinRefDate, 101) AS MinRefDate'); q.ParamByName('dys').AsInteger := 30; q.ParamByName('dt').AsDateTime := StrToDateTimedef('2018-11-01 00:00:00', 2); Thankyou Share this post Link to post
Lajos Juhász 316 Posted March 5 q.SQL.Add('DECLARE @MinEffDate date = DATEADD(DAY, :dys, getdate())'); q.ParamByName('dys').AsInteger := -30; or q.SQL.Add('DECLARE @MinEffDate date = DATEADD(DAY, -1*dys, getdate())'); 1 Share this post Link to post
sp0987 0 Posted March 5 Was it an enhancement in D11? It was working good in D7 Share this post Link to post
sp0987 0 Posted March 5 q.SQL.Add('DECLARE @MinEffDate date = DATEADD(DAY, -:dys, getdate())'); q.ParamByName('dys').AsInteger := 30; It works well in D11 without space too when the query has only this argument. If the query has more than one argument with the combination of "DATEADD(DAY, - :dys, getdate())');" , then it results in error Share this post Link to post