Re: INTERVAL HOUR TO SECOND TO INTEGER
Posted in 1998
I've managed to answer my own question. It's ugly, but it's effective, and it works in just plain SQL. No SPL, no ESQL. Given an INTERVAL HOUR TO SECOND column 'intvl', you do the following: SELECT ( DATETIME(0:00:00) HOUR TO SECOND + intvl ) AS dt FROM table WHERE <exprs> INTO TEMP dttemp; SELECT ( ( (EXTEND(dt,SECOND TO SECOND) || " ") * 1) + (60 * (EXTEND(dt,MINUTE TO MINUTE) || " ")) + (60 * 60 * (EXTEND(dt,HOUR TO HOUR) || " " )) ); The first statement, the SELECT INTO TEMP, simply converts the interval to a datetime. The second statement (the big, ugly one) uses EXTEND to parse out the individual pieces of the datetime (hours, minutes, seconds). It then appends a space to the output, to convert to character, and does arithmetic to convert the character to numeric (there's no direct way to cast from datetime to numeric) and also to convert hours and minutes to seconds. If you wanted to, you could make the syntax uglier and convert intvl to datetime in-line and eliminate the SELECT INTO TEMP. Also, if you're starting with a datetime (which we were in this case), the SELECT INTO TEMP is unnecessary. Thomas J. Girsch wrote in message <363e2238.0@news.one.net>... >I know a similar question came up recently, but does anyone have any idea >how to convert an INTERVAL HOUR TO SECOND to INTEGER? Based on my >application's design, I can't resort to ESQL. > >TIA > >