Thank you in advance! I am working in SQL Server 2008 R2.
What I am trying to do is I have a text type column that has a first and last name and then shows a ^, what I want to do is capture that text leading up to the ^ (so essnetially the first and last name) and append it to the very bottom of another column (not replace) within the same table.
I have tried using charindex but I just receieve the index number and I can’t seem to get it to capture the text before the ^ appears, I just get the position of the ^ and also I am having a hard time appending this
text chunk to another text type column within the same table. For this I have been trying the updatetext function but it doesn’t seem to work. I have scrapped what I have tried thus far because I have gotten anywhere without errors.
So in summary:
I need to capture text at the beginning of a text data type column until it reaches a ^ symbol
Save that text to some sort of variable.
Place (append), along with slight additions, into another text data type column.
It seems like it should be simple but I am having a difficult time, Please make recommendations if possible.
Thank you.
First, let’s find the starting position of the
^incol1:We will then use
LEFTto return the left part of the column by specifying the number of characters to return. However, since the^is at the starting position, we need to subtract 1.We then use
+(CONCATin 2012+) to concatenate another column (col2) to this:If you need to make other additions, you can separate the string values using a plus:
The final statement may look something like:
Update
If there are some values that do not have a
^, you will need aCASEstatement to prevent receiving the “Invalid length parameter passed to the LEFT or SUBSTRING function” error: