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



This is a multipart message in MIME format.
--
[ Picked text/plain from multipart/alternative ]
Had someone here ask me how to convert a date stored in a number (@#$%ing
BPCS) as 8,0 YYYYMMDD, within a SQL statement.  Feeling a little pinched
for time I threw in:
SELECT SCH06, DATE(SUBSTR(DIGITS(SCH06),5,2) || '/' ||
                   SUBSTR(DIGITS(SCH06),7,2) || '/' ||
                   SUBSTR(DIGITS(SCH06),1,4))
FROM EDIMFGCD/PP850D04

While functional, I looked for something better.  CAST doesn't work for
numbers to date.  I thought of creating a UDF based on our internal
dateedit program.

Then I whipped up the following instead:
CREATE FUNCTION NbrToDate
 (Nbr Decimal (8,0))
 Returns Date
 Language SQL
 Returns Null On Null Input
Begin
 Declare WorkDate Char (10);
 Declare ParmDate Date;
 Set WorkDate = substr(Digits(Nbr),5,2) || '/' ||
                substr(Digits(Nbr),7,2) || '/' ||
                substr(Digits(Nbr),1,4);
 Set ParmDate = Date(WorkDate);
 Return ParmDate;
End -- NbrToDate

Now I can do this:
SELECT SCH06, NbrToDate(sch06)
FROM EDIMFGCD/PP850D04

The person had the other method in use already.  Also, they felt that
using the function might cause problems if ERP, and accounting both
started using it and then one or the other wanted to change the function.
Then you would have to figure out an impact of change.  They felt that
having to modify all code containing the conversion manually would be
better.

Can anyone think of a better way to convert the date?

Rob Berendt
--
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety."
Benjamin Franklin


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.