SQLTeam.com | Weblogs | Forums

Truncate a character chain and copy it to another column


I need to truncate a chain of character from one column and copy it to another column.
Ex :
In column A, I have : Value1 _ Value2
Final result required : Value 1 in column A and Value 2 (without the separator '_' ) in column B
Both columns belong to the same table.

Could you help pls?

Thank you

	columnA = LEFT(columnA, CHARINDEX('_',columnA+'_')-1),
	columnB = STUFF(columnA,1,CHARINDEX('_',columnA+'_'),'');

Since this is destructive - i.e., you are losing the orignal value in ColumnA, you might want to test in a dev environment before doing it where it really matters.

Thank you JamesK very much for your help