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.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-05-30 : 09:30:35
|
| philippe writes "Hello ,i am just starting with sql...I have a table: Table_userInside a column user_no (integer)with value like 35678 (about 8000 rows)I would like to modifie all rows of this Table_user.user_nowith a value of 60 at the begining of each value.For example : before 35678 will be 6035678Its'a concatenation,but it's an integer value .so do i need to convert tehm to varchar firstI will appreciate some tips...." |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2006-05-30 : 09:31:40
|
| UPDATE Table_user SET user_no=6035678 WHERE user_no=35678orUPDATE Table_user SET user_no=user_no + 6000000 WHERE user_no=35678 |
 |
|
|
svicky9
Posting Yak Master
232 Posts |
Posted - 2006-05-30 : 11:16:39
|
| hi Rob,I dont think thats the correct query.if you want to concatenate 60 to each and every useridtryupdate table_user set user_no = convert(int,'60'+(convert(varchar(20),user_no)))cheersVic |
 |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-05-30 : 14:06:06
|
Another option is to not stray away from integers, which might be more confusing, but should perform a bit quicker (though I've not tested it ).  --datadeclare @Table_user table (user_no bigint)insert @Table_user select 35678union all select 1union all select 2union all select 123union all select 1213123union all select 1231554575--calculationupdate a set user_no = 60 * power(cast(10 as bigint), floor(log10(user_no )) + 1) + user_nofrom @Table_user aselect * from @Table_user--resultsuser_no -------------------- 603567860160260123601213123601231554575 Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-31 : 01:58:57
|
quote: Originally posted by svicky9 hi Rob,I dont think thats the correct query.if you want to concatenate 60 to each and every useridtryupdate table_user set user_no = convert(int,'60'+(convert(varchar(20),user_no)))cheersVic
The quesioner specified that user_no column is of interger datatype and there is no need to covert it to varchar then integerMadhivananFailing to plan is Planning to fail |
 |
|
|
PSamsig
Constraint Violating Yak Guru
384 Posts |
Posted - 2006-05-31 : 02:10:19
|
| Nice to see high school math hasn't been wasted on you Ryan.-- This one's tricky. You have to use calculus and imaginary numbers for this. You know, eleventeen, thirty-twelve and all those. |
 |
|
|
|
|
|
|
|