Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Numbers

Author  Topic 

JohnBarry
Starting Member

1 Post

Posted - 2012-03-20 : 14:29:44
Hello everyone!

I have a little problems, using PSQL.
I have a long number, for example 123456789 and now i have to increase the 5th number of left by 1. In my example the result would be 123466789.
I am trying to solve this but i failed... somebody an idea?

best regards

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-20 : 14:45:22
UPDATE table
SET Field=STUFF(Field,5,0,SUBSTRING(Field,5,1))

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-03-21 : 07:02:47
quote:
Originally posted by visakh16

UPDATE table
SET Field=STUFF(Field,5,0,SUBSTRING(Field,5,1))

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/




It should be
UPDATE table
SET Field=STUFF(Field,5,1,SUBSTRING(Field,5,1)+1)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-03-21 : 07:06:53
quote:
Originally posted by JohnBarry

Hello everyone!

I have a little problems, using PSQL.
I have a long number, for example 123456789 and now i have to increase the 5th number of left by 1. In my example the result would be 123466789.
I am trying to solve this but i failed... somebody an idea?

best regards


What if the fifth digit is 9?

If the total length is 9, try

select col+10000 from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -