Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Range with strfmt with...
Finance forum

Range with strfmt with different fields

(0) ShareShare
ReportReport
Posted on by 910

Hi,

i try to achieve below sql select with x++. i have two  defirent fields  in where clause: 

SELECT *
FROM TableName
WHERE TableName.date1<= @date or TableName.Date2<= @date

i tried this one but the range not works: 

qbr = qbds.addrange(fieldnum(TableName,Date1));
qbr = qbds.addrange(fieldnum(TableName,date2));
qbr.value(strfmt('((%1.%2 <= %4) || (%1.%3 <= %4))',
qbds.name(),//%1
fieldstr(TableName, date1),//%2
fieldstr(TableName, date2), //%3
ToDate.dateValue())); //%4
qbr.status(RangeStatus::Hidden);

infolog  : 

SELECT * FROM tablename WHERE ((((tablename .date1<= 31\08\2017) || (tablename .date2<= 31\08\2017))))
when i filter i don't get rows, i SQL i get rows

Any help in this issue.

Regards

  • ALAhmed Profile Picture
    ALAhmed 910 on at
    RE: Range with strfmt with different fields

    Thank you for your support.

    Finally using Date2StrXpp() solve my issue  :

    qbr.value(strfmt('((%1.%2 <= %4) || (%1.%3 <= %4))',

    qbds.name(),//%1

    fieldstr(table, date1),//%2

    fieldstr(table, date2), //%3

    Date2StrXpp(_toDate))); //%4

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: Range with strfmt with different fields

    Hi  Alex,

    Please try to use ValidTimeState.

    select validTimeState(fromDateTime, toDateTime) ItemId from table;

    [View:http://dynamics-ax-chronicles.blogspot.com/2011/09/date-effective-tables-with.html:750:50]

  • ALAhmed Profile Picture
    ALAhmed 910 on at
    RE: Range with strfmt with different fields

    Thank you all for the reply.

    using SysQuery::value(ToDate.dateValue()) i get the error :  String value cannot be converted to date value in the where clause. Try using the conversion function.

    using date2StrUsr(ToDate.dateValue()) or Date2StrXpp(ToDate.dateValue())

    no error but no filter

    the query show : SELECT * FROM tablename WHERE ((((tablename .date1<= 31\08\2017) || (tablename .date2<= 31\08\2017))))

    I thank i should convert to 2017-08-31 instead of 31\08\2017

  • Suggested answer
    Khushhal Garg Profile Picture
    Khushhal Garg 1,514 on at
    RE: D365F&O : Range with strfmt with different fields

    In your query ToDate.dateValue() is not returning string which is the issue here. Also, date1 and date2 both belongs to datasource TableName itself so there is no need for %1.%2 or %1.%3 means no need to specify with"tablename." for fields

    try this

    qbr.value(

    strFmt('((%1 <= %3) || (%2 <= %3))',

    fieldStr(TableName,Date1),

    fieldStr(TableName,Date2),

    SysQuery::value(ToDate.dateValue())));

  • Verified answer
    Satish Panwar Profile Picture
    Satish Panwar 14,647 on at
    RE: D365F&O : Range with strfmt with different fields

    Realized that you need less than / greater than ranges...see another thread that explains it well and has example.

    community.dynamics.com/.../how-to-compare-the-date-field-in-query

  • Suggested answer
    Satish Panwar Profile Picture
    Satish Panwar 14,647 on at
    RE: D365F&O : Range with strfmt with different fields

    Hi Alex,

    Take a look at existing thread on similar question.

    community2.dynamics-int.com/.../ax-2012-how-to-use-a-date-range-in-a-query

    Thanks,

    Satish Panwar

    Please take time to click yes against the answer that help guide you in right direction.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans