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 |
|
mavericky
Posting Yak Master
117 Posts |
Posted - 2011-09-22 : 15:52:52
|
| Hi,I have a table 'Student' which has column StuID.StuID has 12000 values in this pattern:1284810111382 1284810111383 1284810111384 1284810111385 1284810111386 1284810111387 1284810111388 1284810111389 1284810111390 I want to get the last 8 characters from all values.I want to create another column called as ID which should values:101113821011138310111384101113851011138610111387101113881011138910111390Can anyone help me how this can be done?Thanks in anticipation,Mavericky |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Ehan
Starting Member
19 Posts |
Posted - 2011-09-22 : 16:19:58
|
| alter table Student add ID as (RIGHT(StuID,8)) if you want to physically store computed column add persistedalter table Student add ID as (RIGHT(StuID,8)) PERSISTED |
 |
|
|
mavericky
Posting Yak Master
117 Posts |
Posted - 2011-09-22 : 16:20:31
|
| Thanks for the reply but it's not always 12848, there are other 5 digit characters too int the column. Is it still possible? |
 |
|
|
mavericky
Posting Yak Master
117 Posts |
Posted - 2011-09-22 : 16:35:32
|
| Thanks a lot!!! This solved my problem. |
 |
|
|
mavericky
Posting Yak Master
117 Posts |
Posted - 2011-09-22 : 16:56:00
|
| Actually, this code solves the issue but i want the datatype of the column to be int. Right now the datatype shows blank and it is uneditable. Can this be done? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-22 : 22:40:23
|
| [code]UPDATE StudentSET ID=StuID%100000000[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|