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
 LTrim/Rtrim memory lapse

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

Posted - 2011-11-14 : 15:41:42
Could you show us some data samples to make this more clear?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

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 Shaw
SQL Server MVP
Go to Top of Page

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.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-14 : 16:14:43
Here's how you would do it for your data sample:

SET OffenseNo = 'RCSO00OFF' + LEFT(OffenseNo, 6)

Now if this doesn't really handle everything you need, please post more data samples. One is almost never enough.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -