help with an update statement and CAST()

i have a table wich i need to update
my intention is to update the field increasing 100 to its current value, unfortunately that value is stored as string

for example '0165' would like to turn it into "0265'
so my approach was to use cast to turn that into a value increase it by 100 then turn it into a character and padding it with a 0, but the next statement is not working, im very new to firebird and i was looking for a TONUMBER or VAL function, im most used to oracle and/or mssqlserver

update CHECADAS
set
 CHECADAS.CH_H_REAL='0'||cast(CAST(CH_H_REAL AS  NUMERIC)+100 as character(800))
where
  CH_H_AJUS = '0630';



please help this is urgent, that system didnt consider day time savings and i need to update the records (check in time values) for all those who checked-in  with a wrong time (one hour ahead of time)


LVL 12
aranaAsked:
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.

Nick UpsonPrincipal Operations EngineerCommented:
update CHECADAS
set
 CH_H_REAL='0'||cast(CAST(CH_H_REAL AS  INTEGER)+100 as char(800))
where
  CH_H_AJUS = '0630';

if this doesn't work, please explain exactly what does happen, error message or ?

I've changed numeric to integer as cast to numeric will give 630.00
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
Pierre CorneliusCommented:
What type is the field CH_H_REAL?

Assuming it is of CHAR(4), you should rather casting to "char(3)" instead of casting to "char(800)"
0
Gary BenadeCommented:
I assume you want to change all the 0630 (a time?) to 0730, so why dont you just do this?

update CHECADAS
set
 CH_H_REAL = '0730'
where
  CH_H_AJUS = '0630';
0
aranaAuthor Commented:
this was so urgent it was solved by editing one by one from the client application (about 300 records only affortunately) so even if any of the suggestion works its of of no use right now, but i  still want the solution just to know why this damn thing isnt working and maybe learn something along the way.

tried the INTEGER approach

"I've changed numeric to integer as cast to numeric will give 630.00"
i tried this, this is the error:
with numeric:
*****************************************************
ISC ERROR CODE:335544321

ISC ERROR MESSAGE:
arithmetic exception, numeric overflow, or string truncation

Statement: update CHECADAS
set
 CH_H_REAL='0'||cast(CAST(CH_H_REAL AS numeric)+100 as char(800))
where
 CH_H_AJUS = '0630'
******************************************************

with integer:
**************************************************
ISC ERROR CODE:335544321

ISC ERROR MESSAGE:
arithmetic exception, numeric overflow, or string truncation

Statement: update CHECADAS
set
 CH_H_REAL='0'||cast(CAST(CH_H_REAL AS INTEGER)+100 as char(800))
where
 CH_H_AJUS = '0630'
***************************************************

tried both with CHAR(3) and same thing happens




"What type is the field CH_H_REAL?"
CHAR(4)


"I assume you want to change all the 0630 (a time?) to 0730, "
your assumption is not right, 0630 is another column, we dont know the value of ch_h_real.
i need to add 100 to ch_h_real value (no matter what it is) whenever the ch_h_ajus is 0630
0
Pierre CorneliusCommented:
>>>but i  still want the solution just to know why this damn thing isnt working and maybe learn something along the way.

You will get errors when casting to char(800) as your field can only hold 4 chars.

You say you got the error even when casting to Char(3)? My best guess is that the problem lies with the other part of your statement then i.e.  the part "CAST(CH_H_REAL AS INTEGER)". Most likely you have certain rows with null values so the error results because it cannot cast a null value to an integer.

The following probably would have sorted out your problem:

set
 CH_H_REAL='0'||cast(CAST(CH_H_REAL AS INTEGER)+100 as char(800))
where
 CH_H_AJUS = '0630' AND CH_H_REAL is not null

Regards
Pierre
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
Databases

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.