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 |
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2011-11-14 : 15:34:00
|
| I know i know how to do this, but i'm forgetting what i knew.I have an LTRIM statement that i'm using to change the first set of characters from a string. Turns out, i also need to replace the last six characters from a string based on another column's value, which itself, is longer than six characters. here is my LTRIM statement as it is now:SET EVPNO=LTRIM(RTRIM(REPLACE(EVPNO,'RAV00EVP000','RCSO00EVP00')))Now, the column in my table which contains the characters i need to RTRIM in is "OFFENSENO". The length of that columns strings are 8 charachters. I need my new EVPNO to be what which you see above in the Ltrim, but concatenated with the first 6 characters of the OFFENSENO string for each row. what's my syntax for adding that RTRIM command to this statement? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-11-14 : 15:45:33
|
| LTRIM and RTRIM just remove leading and trailing spaces. I suspect the functions you want are LEFT, RIGHT and SUBSTRING.LEFT(<column name>,6) will get you the first 6 characters of that column.--Gail ShawSQL Server MVP |
 |
|
|
WJHamel
Aged Yak Warrior
651 Posts |
Posted - 2011-11-14 : 15:49:47
|
| OffenseNo: 99120376 I need the new Offenseno to be (in the above case):RCSO00OFF991203.I may have misstated some of the details in the first posting about this. nonetheless, what you see here is what i need. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-14 : 23:44:49
|
quote: Originally posted by WJHamel OffenseNo: 99120376 I need the new Offenseno to be (in the above case):RCSO00OFF991203.I may have misstated some of the details in the first posting about this. nonetheless, what you see here is what i need.
is it always 'RCSO00OFF' that needs to be prefixed? or is it based on some other rule?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|