We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

SQL - string manipulation and copying - SQL Server 2005

Medium Priority
276 Views
Last Modified: 2012-05-11
Hello experts,

I have a table with two columns that I would like to move data from one to the other.  The table looks like:

table: mwc_notes_raw
note_id            note_type
1010 0GEN      null
3013 0GEN      null
4013 0INS        null
1919 0INS        null

I want to split apart t he note_id column and copy everything after the first blank space to the note_type column, and remove everything after the space from the first column, and end up with:

table: mwc_notes_raw
note_id            note_type
1010               0GEN
3013               0GEN
4013               0INS
1919               0INS

Something like:

update mwc_notes_raw
set note_type = RIGHT(Notes_primary_Key,charindex(' ',reverse(Notes_primary_Key))-1),
set Notes_primary_Key =LEFT(Notes_primary_Key,charindex(' ',reverse(Notes_primary_Key))-1)

Thoughts?

Thanks!
Comment
Watch Question

CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Software Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thanks!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.