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
 Update on a integer field

Author  Topic 

philippe1024
Starting Member

1 Post

Posted - 2006-05-29 : 10:46:23
Hi everybody,
Could someone help me ???
Iam starting with sql

My problem ..

Ihave a table Table_customer

In this table a column Table_customer.no
This column contain 8000 rows.
with customer numbers: like 30789
I would like to modify once all this row adding just before the number
a value to all these rows.This value will be a 60
So will have instaed of 30789 a 6030789
This column is an integer.

I have try a simple select wich give me this result
How i can do this with update ?
probably i have to convert fisrt to caracters

select kunr,nov_kunr=
'30'+ltrim(str(kunr))
from event
where kunr is not null

Thank


spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-05-29 : 11:08:10
update table_cutomer
Set id = 6000000 + id
where some condition

Go with the flow & have fun! Else fight the flow
Blog thingie: [URL="http://weblogs.sqlteam.com/mladenp"]
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-05-29 : 12:27:13
philippe1024,

Do u want to add the 2 characters '6' & '0' in front or add a 6000000 to the customer numbers
Both will givethe same results as ling as customer numbers < 99999

if u want to precede with 2 characters '60' in front of any customer #
u may need to convert the customer # to varchar & concatenate that with '60'
eg.
Set @custNum = '60' + convert(varchar(20), '30789' )
or
Set id = '60' + convert(varchar(20), id)

if u want to update the table with that value, u may need to convert it back to int
(may be for a larger value the int size may be insufficient, so that u may need to go for bigint



Srinika
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-05-30 : 14:10:25
Duplicate post: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=66948

Ryan Randall
www.monsoonmalabar.com London-based IT consultancy

Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page
   

- Advertisement -