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 fields using data in existing field

Author  Topic 

kangle
Starting Member

5 Posts

Posted - 2015-01-15 : 14:12:06
I hope this forum is appropriate for my question. I have a field where all of the data is 5 characters in length. The last character denotes a status and will always be an F, H, or T. I want to add a new field (which I will do manually) and populate the new field with the last character from the "old" field. Once that is complete, I want to eliminate that 5th character from the old field.

OLD FIELD NEW FIELD
B123F
B123H
B123T

OLD FIELD NEW FIELD
B123 F
B123 H
B123 T

I assume the formatting may be lost but hope the description above is adequate to describe what I am trying to accomplish. Thanks in advance for any assistance you can provide.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-15 : 14:16:51
Please test:
UPDATE t1
SET NewColumn = RIGHT(OldField,1), OldColumn = LEFT(OldColumn, 4)

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

kangle
Starting Member

5 Posts

Posted - 2015-01-21 : 11:19:57
Thank you Tara. Hopefully my SQL install will be repaired this afternoon and I will have an opportunity to test.

Thanks again
Go to Top of Page
   

- Advertisement -