Using Substring AND math on the same column

I am trying to do math on a column, then substring it so I can convert it to a time like value.  The field is a number field that contains HHMM.  I am subtracting another column from it that is in thousanths of a second.  The math works alone.  The substring works alone.  Put both together and it fails.

Here is the math:  select (ENDRUN*60)-(ELAPTIME/100))/60 from CMR_RUNINF

Here is the substring: substring(ENDRUN,1,2)

Here is both:  
select JOBNAME, MEMNAME, NODEID, STARTRUN as "DATE", substr(((ENDRUN*60)-(ELAPTIME/100))/60),1,2) as "START TIME", ENDRUN as "END TIME", ELAPTIME/100 as "Minutes" from CMR_RUNINF order by JOBNAME

Here is my error:
System.Data.OleDb.OleDbException: The data type int is invalid for the substring function,
Allowed types are: char/varchar, nchar/nvarchar, and binary/varbinary.

What am I missing?

What is the Oracle equivelant (I need to run this against both DB types!)
JRamos1200Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fefo_33065Commented:
Convert it to string first,

select JOBNAME, MEMNAME, NODEID, STARTRUN as "DATE", Convert(char,substr(((ENDRUN*60)-(ELAPTIME/100))/60),1,2)) as "START TIME", ENDRUN as "END TIME", ELAPTIME/100 as "Minutes" from CMR_RUNINF order by JOBNAME

I hope this helps,

Fefo

ps: Not familiar with Oracle
0
fefo_33065Commented:
OOps,

The other way around:


JOBNAME, MEMNAME, NODEID, STARTRUN as "DATE", substr(Convert(char,((ENDRUN*60)-(ELAPTIME/100))/60)),1,2) as "START TIME", ENDRUN as "END TIME", ELAPTIME/100 as "Minutes" from CMR_RUNINF order by JOBNAME


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Renante EnteraSenior PHP DeveloperCommented:
Hi JRamos1200!

By the way, could you double-check your posted code ???  I think there's a problem on this part :
   substr(((ENDRUN*60)-(ELAPTIME/100))/60),1,2) as "START TIME",

It should be : substr(((ENDRUN*60)-(ELAPTIME/100)/60),1,2) as "START TIME",

Remove extra ")" before "/60".  Just correct me if I'm wrong.

And to answer your question, you could also do it using CAST() function.

Here is the code :

select JOBNAME, MEMNAME, NODEID, STARTRUN as "DATE", substr(cast(((ENDRUN*60)-(ELAPTIME/100)/60) as varchar(10)),1,2) as "START TIME", ENDRUN as "END TIME", ELAPTIME/100 as "Minutes" from CMR_RUNINF order by JOBNAME

Hope this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0
JRamos1200Author Commented:
That did got the results I expected, Thanks!  Now I just need to re-think my logic as I was doing bad date math!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.