Skip to main content

Notifications

Announcements

No record found.

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

Range with strfmt with different fields

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,512 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,641 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,641 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.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

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

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans