Jump to content
sp0987

Argument out of range Exception

Recommended Posts

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



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())');

  • Like 1

Share this post


Link to post

Was it an enhancement in D11? It was working good in D7

 

 

Share this post


Link to post

 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×