× 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.



On 17-Nov-2011 05:33 , rob@xxxxxxxxx wrote:
<<SNIP>>

CREATE FUNCTION ROUTINES.DATETONUM ( REALDATE DATE )
RETURNS DECIMAL(8, 0)
LANGUAGE SQL
<<SNIP>>
BEGIN
DECLARE NUMDATE DECIMAL ( 8 , 0 ) ;
SET NUMDATE = INT(
YEAR ( REALDATE )
|| RIGHT ( '0' || MONTH ( REALDATE ) , 2 )
|| RIGHT ( '0' || DAY ( REALDATE ) , 2 )
) ;
RETURN ( NUMDATE ) ;
END ;

<<SNIP>>

OT: FWiW, the following rewrite of that SQL UDF rids of the concat symbols, the breaking down of the date components, those components reconstituting the composite date using the concatenation, and the intermediate variable for which BEGIN\END are required; returning the numeric string of digits implicitly cast to the declared return-as data type with just one reference to the input parameter in the expression with just two scalar functions:

CREATE FUNCTION ROUTINES.DATETONUM ( REALDATE DATE )
RETURNS DECIMAL(8, 0)
LANGUAGE SQL
<<SNIP>>
RETURN REPLACE( CHAR( REALDATE, ISO ) , '-', '' ) ;

I do not _know_ which would be faster, but I would guess the latter.

Regards, Chuck

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.