Very Hot Topic (More than 25 Replies) Using Pipes in Retrieve Specs (Read 3859 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Using Pipes in Retrieve Specs
Sep 19th, 2007 at 10:53am
Print Post Print Post  
In another thread, Erika wrote:
Quote:
use ">|@Date - 30|" .... It will also run faster than your programmed retrieve spec.


Hi Erika!

I remember you mentioning this at the conference, and I made a note that it was important to me, but I've forgotten just how and in what instances Piping should be used.  Can you explain its use in a bit more detail?

Is it just for date calculations?  Should I place pipes around all my date manipulations (and by all I mean form programming as well as report programming)?  Would it serve any purpose in a programming calculation such as:
Code
Select All
Invoice_Age = @ToNumber(@Date) - @ToNumber(Invoice_Date) 


or a report calculation such as:
Code
Select All
Var MonthTotal as Double
MonthTotal = @ToMoney(@XLookup("MonthTotals.db", @Year(@Date) - 1, "Year", @Month$(@Date)))
Last_Year = "Last year's total for " + @Month$(@Date) + " was:  $" + @STR(MonthTotal) 


Or is it just for retrieve specs?  Here's one I use to retrieve this month's invoices:
Code
Select All
{@Year(Invoice_Date) = @Year(@Date) AND @Month(Invoice_Date) = @Month(@Date)} 


How would piping be used on that?  Is it as simple as replacing the curly braces?

Thanks!
« Last Edit: Sep 19th, 2007 at 2:13pm by Hammer »  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Piping
Reply #1 - Sep 19th, 2007 at 11:18am
Print Post Print Post  
Scott,

This is only for retrieve specs.

You can use it on any programming statement that does not refer to a record value, such as @Date, @UserID, etc.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Piping
Reply #2 - Sep 19th, 2007 at 11:28am
Print Post Print Post  
Quote:
{@Year(Invoice_Date) = @Year(@Date) AND @Month(Invoice_Date) = @Month(@Date)}

You can't use the pipe for this because it refers to a record value - Invoice_Date. I believe there is a way to construct a retrieve that will work. I'm not where I can test though. I'll try to post it later.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Piping
Reply #3 - Sep 19th, 2007 at 12:59pm
Print Post Print Post  
Hello Scott,

If you put the following in the Invoice Date element it will do the same thing as your programmed retrieve, but faster.

Code
Select All
]|@Year(@Date)|/|@Right("00" + @Str(@Month(@Date)), 2)|/.. 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Piping
Reply #4 - Sep 19th, 2007 at 1:25pm
Print Post Print Post  
Holy guacamole, what the heck is that?  But hey, it works.  Can you explain it to me?  And where should I put the "-1" for 1) Last month's and 2) last year's.

Thanks Ray!
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Piping
Reply #5 - Sep 19th, 2007 at 1:27pm
Print Post Print Post  
I can make sense out of all of it except "@Right("00" + @Str(@Month(@Date)), 2)".

Note to interested onlookers:  Do not do this:
Code
Select All
]|@Year(@Date)|/|@Right("00" + @Str(@Month(@Date)), 2)-1|/.. 




  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Piping
Reply #6 - Sep 19th, 2007 at 1:38pm
Print Post Print Post  
@Right("00" + @Str(@Month(@Date)), 2) pads the month number out to two places. A date is stored as YYYY/MM/DD, where MM is the month. For September it is stored as 09 but @Month simply returns 9 so we need the other zero before it, so that the retrieve works.

Last month is tricky as last month may have been December and subtracting 1 from 1 does not give you 12 nor does it give you the right year. It's gonna be a tricky statement.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Piping
Reply #7 - Sep 19th, 2007 at 1:40pm
Print Post Print Post  
This got me August's:
Code
Select All
]|@Year(@Date)|/|@Right("00" + @Str(@Month(@Date)-1), 2)|/.. 


But I see what you mean about December.  Hmmm.
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Piping
Reply #8 - Sep 19th, 2007 at 1:41pm
Print Post Print Post  
Explanation:

] <-This character makes it a string search instead of a date search

|@Year(@Date)| <- This gets the current year

/ <-This inserts a slash into the criteria

|@Right("00" + @Str(@Month(@Date)), 2)| <-This gets the month number padded to two numbers as described above

/.. <-This inserts a slash and then dot dot for any day in that month

So what you end up with(If you look at it after the compiler) is

]2007/09/..

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Piping
Reply #9 - Sep 19th, 2007 at 1:43pm
Print Post Print Post  
I think this will give you last months

Code
Select All
]|@Year(@Date-@DOM(@Date))|/|@Right("00" + @Str(@Month(@Date-@DOM(@Date))), 2)|/..  



-Ray
« Last Edit: Sep 19th, 2007 at 3:22pm by Ray the Reaper »  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Piping
Reply #10 - Sep 19th, 2007 at 1:44pm
Print Post Print Post  
For all of last year it would be

Code
Select All
]|@Year(@Date)-1|/.. 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Piping
Reply #11 - Sep 19th, 2007 at 1:58pm
Print Post Print Post  
Wow, you are amazing.  The one for last month nicely retrieves August.  I'll put it in play and see what happens in January.  Thanks Ray!
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Piping
Reply #12 - Sep 19th, 2007 at 2:09pm
Print Post Print Post  
I've been having fun with these; I've crashed Sesame 4 times because I've put the math in the wrong places.  But when the smoke cleared:

This month last year
Code
Select All
]|(@Year(@Date-@DOM(@Date))-1)|/|@Right("00" + @Str(@Month(@Date)), 2)|/..   



Last month last year
Code
Select All
]|(@Year(@Date-@DOM(@Date))-1)|/|@Right("00" + @Str(@Month(@Date-@DOM(@Date))), 2)|/..   



I now have a nice little library of programmed retrieves that make use of piping and are not tied to an element.  Thanks Ray and Erika!
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Piping
Reply #13 - Sep 19th, 2007 at 2:12pm
Print Post Print Post  
Can you send us one that crashes? We'd like to intercept whatever evil is caused if you put the math in the wrong place. Please send it to Support as opposed to posting it here. I don't want to confuse someone who is skimming.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Using Pipes in Retrieve Specs
Reply #14 - Sep 19th, 2007 at 2:15pm
Print Post Print Post  
Well, one is already posted above as something not to do.  I'll mail the others.
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Piping
Reply #15 - Sep 19th, 2007 at 3:30pm
Print Post Print Post  
Infinity wrote on Sep 19th, 2007 at 1:58pm:
Wow, you are amazing.  The one for last month nicely retrieves August.  I'll put it in play and see what happens in January.  Thanks Ray!



If it works for August, then it's going to work For January. I wrote it from memory and thought I had forgot something. Just so that you know what it is doing. The Statement
Code
Select All
@Date-@DOM(@Date) 

takes you back to the last day of the month before this one. So the Year and the Month statements will return the Year and Month of the last day of the month before this one.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Using Pipes in Retrieve Specs
Reply #16 - Sep 19th, 2007 at 11:05pm
Print Post Print Post  
Temporarily change your system date to January to test it out.

Remember to change it back again.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Using Pipes in Retrieve Specs
Reply #17 - Sep 20th, 2007 at 12:12am
Print Post Print Post  
Bob_Hansen wrote on Sep 19th, 2007 at 11:05pm:
Temporarily change your system date to January to test it out.

Remember to change it back again.

A safer method (more work, but safer) is to replace @Date with @GlobalValue("TestDate"), which would be set with something like GlobalValue("TestDate", "2008/01/10").

EDIT: Alec Mulvey wrote an Inside Sesame article about why you shouldn't change the system date, on page 5 of the July 2006 issue. He suggests using a variable, which is probably better anyway, since it won't leave debris in the GlobalValues table.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Using Pipes in Retrieve Specs
Reply #18 - Sep 20th, 2007 at 4:04am
Print Post Print Post  
Good reminder Carl. and thanks to Alec for the article.  I have used Alec's method and agree with using the format of "yyyy/mm/dd".  Usually the easiest and most reliable.

I had a similar experience where some trial software thought it had been expired, and I had to remove, edit registry values, redownload, and reinstall.  We are lucky that Sesame provides us the tools to do that.  Can't always do that with other programs that need dates/times in the testing.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Using Pipes in Retrieve Specs
Reply #19 - Sep 20th, 2007 at 1:02pm
Print Post Print Post  
Quote:
EDIT: Alec Mulvey wrote an Inside Sesame article about why you shouldn't change the system date, on page 5 of the July 2006 issue. He suggests using a variable, which is probably better anyway, since it won't leave debris in the GlobalValues table.


In this case you would have to use a GlobalValue or a hardcoded date as it is Retrieve Spec programming that does not have variables.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Using Pipes in Retrieve Specs
Reply #20 - Sep 21st, 2007 at 12:01am
Print Post Print Post  
Quote:
In this case you would have to use a GlobalValue or a hardcoded date as it is Retrieve Spec programming that does not have variables.

Oh, yeah. Thanks for reminding me why I suggested GlobalValues in the first place. Cheesy
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: Using Pipes in Retrieve Specs
Reply #21 - Sep 23rd, 2010 at 11:28am
Print Post Print Post  
Hello!
How to use the pipe to retrieve last week or this week:
Now i use for this week retrieve: { Eingang > @Date - @Dow(@Date) AND Eingang <= @Date - @Dow(@Date) +7 }

Thank you for the help.

Dr. Belhareth
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Using Pipes in Retrieve Specs
Reply #22 - Sep 23rd, 2010 at 12:12pm
Print Post Print Post  
Your example only retrieves this week's records. The first half needs to have a "-7" in there, like this:
Code
Select All
{ Eingang > @Date - @Dow(@Date) -7 AND Eingang <= @Date - @Dow(@Date) +7 } 



Which can then be put inside pipes like this:
Code
Select All
>|@Date - @Dow(@Date) -7|..<=|@Date - @Dow(@Date) +7| 



Note that it must be placed in the Eingang LE.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Amor
Full Member
Members
***
Offline


No personal text

Posts: 366
Location: Germany
Joined: Feb 7th, 2004
Re: Using Pipes in Retrieve Specs
Reply #23 - Sep 23rd, 2010 at 12:16pm
Print Post Print Post  
Hello Carl!

>|@Date - @Dow(@Date) -7|..<=|@Date - @Dow(@Date) +7|  this give the last seven days.

>|@Date - @Dow(@Date)|..<=|@Date - @Dow(@Date) +7| to  retrieve the days of this week.

thanks.
  

Dr. med. Amor Belhareth&&Medizin Labor &&Germany
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1350
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Using Pipes in Retrieve Specs
Reply #24 - Sep 23rd, 2010 at 12:50pm
Print Post Print Post  
Quote:
>|@Date - @Dow(@Date) -7|..<=|@Date - @Dow(@Date) +7|  this give the last seven days.

Actually, to clarity, this will find all of last week AND all of this week - not just the last 7 days. Meaning as of today (09/23/2010) it will find dates from 09/13/2010 through 09/26/2010, which also includes dates a few days into the future.

Quote:
>|@Date - @Dow(@Date)|..<=|@Date - @Dow(@Date) +7| to  retrieve the days of this week.

Again, as of today (09/23/2010), this will find dates from 09/20/2010 through 09/26/2010. This one is like you indicated, but I wanted to clarify it for onlookers.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Using Pipes in Retrieve Specs
Reply #25 - Feb 28th, 2011 at 8:57pm
Print Post Print Post  
Waaay back when, Ray wrote:

Quote:
I think this will give you last months
Code
Select All
]|@Year(@Date-@DOM(@Date))|/|@Right("00" + @Str(@Month(@Date-@DOM(@Date))), 2)|/..   



How would I adapt this to show 2 month's ago?  I've tried putting "-1" inside various parenthesis, but I can't get it to retrieve anything from December.  Is it because the year changed?

Thanks for your help.
  

**
Captain Infinity
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Using Pipes in Retrieve Specs
Reply #26 - Feb 28th, 2011 at 9:07pm
Print Post Print Post  
Answering my owe  question, it does fail because the year changed.  Changing my system time and using the following will retrieve January's invoices:

Code
Select All
]|@Year(@Date-@DOM(@Date))|/|@Right("00" + @Str(@Month(@Date-@DOM(@Date))-1), 2)|/.. 



Is there a generic fix that retrieve two months ago in spite of the year change?

Thanks again for your help.
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Using Pipes in Retrieve Specs
Reply #27 - Feb 28th, 2011 at 9:28pm
Print Post Print Post  
Hello Scott,

Try

Code
Select All
]|@Year(@Date-@DOM(@Date)-@DOM(@Date-@DOM(@Date)))|/|@Right("00" + @Str(@Month(@Date-@DOM(@Date)-@DOM(@Date-@DOM(@Date)))), 2)|/.. 



-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Using Pipes in Retrieve Specs
Reply #28 - Feb 28th, 2011 at 9:46pm
Print Post Print Post  
BOOYAH!  Ray, you are the BEST!  Works like a charm!

(When you've got a minute, could you break down what it's doing?  Thanks!)
  

**
Captain Infinity
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Using Pipes in Retrieve Specs
Reply #29 - Feb 28th, 2011 at 10:03pm
Print Post Print Post  
Hello Scott,

I'll try to take a few minutes tomorrow and break it down for you.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Using Pipes in Retrieve Specs
Reply #30 - Mar 1st, 2011 at 2:26pm
Print Post Print Post  
Hello Scott,

Since you know what most everything else does I'm going to focus on this part of the syntax that repeats itself

Code
Select All
@Date-@DOM(@Date)-@DOM(@Date-@DOM(@Date)) 



What this does is it goes to the last day of the month 2 months before the current one. And here is how it does that.

Let's use February 28th 2011 as the current date in this example. So let's substitute that in

Code
Select All
2011/02/28 - @DOM(2011/02/28) - @DOM(2011/02/28 - @DOM(2011/02/28)) 



Now let's solve for @DOM() of today's date

Code
Select All
2011/02/28 - 28 - @DOM(2011/02/28 - 28) 



2011/02/28 minus 28 is 2011/01/31 so let's substitute that in

Code
Select All
2011/01/31 - @DOM(2011/01/31) 



Again let's solve for @DOM()

Code
Select All
2011/01/31 - 31 



and we reach the result of

Code
Select All
2010/12/31 



Okay now we know that for February 28th 2011 this piece of code below resolves to 2010/12/31

Code
Select All
@Date-@DOM(@Date)-@DOM(@Date-@DOM(@Date)) 



So let's substitute that into the original piece of code.

Code
Select All
]|@Year(2010/12/31)|/|@Right("00" + @Str(@Month(2010/12/31)), 2)|/..  



Make a bit more sense now?

-Ray



  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Using Pipes in Retrieve Specs
Reply #31 - Mar 1st, 2011 at 3:32pm
Print Post Print Post  
Wow, that's amazing.  Thanks Ray!
  

**
Captain Infinity
Back to top
IP Logged