I think if you make the function deterministic then it might perform better
(if you have a lot of rows with the same value for date). The only way to be
sure is a test, but you would have to be careful, as I am not sure of the
lifecycle of the iSeries cached function responses.
I also think using the function might make your SQL a little more readable
too, a good descriptive function name can make all the difference in
understanding the business logic.
Based on your narrative I'd call the function IsInOpenPeriod(date)
-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Mike Wills
Sent: 09 February 2011 21:39
To: midrange-l@xxxxxxxxxxxx
Subject: To function or not to function, that is the question at hand
I am working on some SQL statements for an ASP.NET application. One of the
things that is required is to only display information in an open period.
The period is updated automatically by the vendor software as the previous
period is closed. So I finding myself doing a bunch of sub selects like:
where date >= (SELECT DATE(CONCAT('20', CONCAT(YY, CONCAT('-', CONCAT( MM,
(CONCAT('-', DD))))))) FROM LIB/FILE')
Yes, each portion of the date is in separate fields.
Would making this query a function make the query more efficient? I have
never created a function before how would I do that? My thought is having
something like:
IsInRange(date)
So I can do "WHERE IsInRange(date)".
Or is there a better way?
--
Mike Wills
http://mikewills.me
As an Amazon Associate we earn from qualifying purchases.