× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



From performance standpoint, you're better of casting the DATE so it matches
up with your field's data type (NUMERIC(8,0)). Reason behind that is that
now you give query optimizer a chance to use an existing index over that
field (if any keyed LF or SQL Index with that field as a key exist).

The other way around (casting numeric to date), you have no prayer of using
an index. If tables are large, you WILL feel the difference.

Now, if you changed the field to DATE data type you wouldn't dwell on this
little factoid :)

Elvis

Celebrating 10-Years of SQL Performance Excellence on IBM i5/OS and OS/400
http://centerfieldtechnology.com/training.asp


-----Original Message-----
Subject: Re: SQL Date Math

Very nice...thank you.

On Nov 13, 2007 1:21 PM, Wilt, Charles <WiltC@xxxxxxxxxx> wrote:
create function CvtDateToNumISO(indte date) returns numeric(8,0)
language SQL
not fenced
deterministic no external action
specific CvtDateToNumISO
returns null on null input
contains SQL
set option datfmt=*ISO
begin
return( ( year(inDte) * 10000) +
( month(inDte) * 100) +
( day(inDte) ) );
end;



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.