Jump to content

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


scotchegg78

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 :)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.