Jump to content

[SOLVED] Quick question! extract string into 2 parts from txt column seperated by ,


Recommended Posts

Hi guys

 

I have a var 255 column called data which has the format ' part1,part2'.

 

I want to extract and put part1 into its own column, and part2 into its own column.

 

so something like update table set part1 = data(part1);

 

What can i use to match all text before the , a reg expression??

 

thanks

 

 

 

If you are querying the database directly then try using a substring combined with a charindex to get the position of the comma as this will probably vary with the different string lengths.

thanks i used this

 

update table set part1 = (substring_index(data,',',1)) for first part and

update table set part2 = (substring_index(data,',',-1)) for the 2nd part

 

maybe a better way, but it did hte job :)

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.