Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Problem with subtracting field value from today( ) in SELECT statement where clause

Posted on by
Hi,
 
I am having an issue with trying to subtract from the today( ) in the where clause of a SELECT statement. 
 
I am using the SalesLine to get the warehouse in InventDim, which is then used to get the number of days in the past in a custom table.  This number of days is used to subtract from today's date to determine whether to process or not. It is of type Integer, has no EDT, and has the value 14.
 
The sample code is below, and if I substitute the field for the number of days in the past by hardcoding, it works.  Are you not allowed to subtract a integer field value from today( )? 
 
Thanks in advance!
 
    SalesLine           salesLine;    
    InventDim           inventDim;
    myCustomParmTable   customParmTable; // has two fields: InventLocationId, NumDaysInPast (type Integer; value = 14)     
    
    SalesId         _salesId = 'SO-00001001';     
    ;       
    while select salesLine 
        where salesLine.SalesId == _salesId
        join inventDim  
            where inventDim.inventDimId == salesLine.InventDimId
                join customParmTable
                    where customParmTable.InventLocationId == inventDim.InventLocationId &&
                          salesLine.ConfirmedDlv >= today() - 14                                 // <-- this goes in loop  
 //                       salesLine.ConfirmedDlv >= today() - customParmTable.NumDaysInPast      // <-- this doesn't go in loop           
    {
        // process SO line
        info("Inside while loop");  
    }
  • Suggested answer
    Anton Venter Profile Picture
    Anton Venter 10,547 Super User on at
    Problem with subtracting field value from today( ) in SELECT statement where clause
    Hello,
     
    It's not possible to do arithmetic in the where clause using a joined table as in your example. I suggest to populate a temporary table with your data (subtracting the number of days for each line) first and then join with this temporary table.
     
    By the way use systemDateGet() instead of today() or is there a reason for using today()?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,768 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,985 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans