How to setup system date in a query

Get our Free Newletter

Don't you have the time to be online here at DUG every day? So how do you follow what is going on in the Dynamics industry and community?
If you subscribe to the DUG Newsletter then you can relax! We will make sure that you don't miss the big news!

Check out our
Newsletter Subscription Center
page a complete list of our different newsletters.

Not Answered This post has 0 verified solutions | 1 Reply | 1 Follower

1 Posts
10 Points
Joined: 2012-10-18
Last Online:
2012-10-19 22:02
freq1 posted on 2012-10-18 21:03

I need some help writing a query..

What I need is 'Select priceDicTable where PriceDiscTable.ItemRelation == mbsbdVendPriceIncreaseLines.ItemID && PriceDiscTable.AccountRelation == mbsbdVendPriceIncreatseLines.AccountNum && PriceDiscTable.FromDate >= sysdate() && PriceDiscTable.ToDate <= sysdate()

I'm having a hard time figuring out how to setup the >= sysdate.

What I have so far is ..

query = new Query();

    qbds = query.addDataSource(tablenum(priceDiscTable));
    qbds.addRange(fieldnum(priceDiscTable,ItemRelation)).value(queryValue(mbsbdVendPriceIncreaseLines.ItemID));
    qbds.addRange(fieldnum(priceDiscTable,AccountRelation)).value(queryValue(mbsbdVendPriceIncreaseLines.AccountNum));

I need to setup another range statement to include the sysdates.

All Replies

Male
253 Posts
5,015 Points
Joined: 2009-6-17
Last Online:
2013-5-2 13:41
Location: Aarau, Switzerland
Janis Cehovs replied on 2012-10-18 22:21

Hi,

try this:

qbds.addRange(fieldnum(priceDiscTable,FromDate)).value(queryRange(systemdateget(), datemax())));

qbds.addRange(fieldnum(priceDiscTable,ToDate)).value(queryRange(datenull(), systemdateget())));

I don't want to log on to a system tonight to proof it, but I guess it should be ok.

Also are you sure that this is correct: PriceDiscTable.FromDate >= sysdate() && PriceDiscTable.ToDate <= sysdate()  ?   Whether I might have had too much wine tonight, or I don't get what you want to achieve with such date range (FromDate is in the future, ToDate is in the past...  weird. Most likely with such date range you will only select records that have both From- and ToDate equal with today's date). Do you really have one day prices in system?

 

Janis.

Page 1 of 1 (2 items) | Get this RSS feed | Bookmark and Share