Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

CASE WHEN THEN using CHARINDEX

$
0
0

Hello,

I have a table with 3 colums - ClientName, ClientInital, ClientSurname

Client Name is populated with both of the following:

Bloggs, Joe

CA11 ABC

I know! Full names separated with a comma and postcodes. There is some other stuff in this column as well but whatIhave to do is to put the get the data and put it into the initial and surname columns. For the post code the Initial will beC and the surname A11ABC

The following code works in my table ( I am splitting it up so that it works. I' don't know how to put this together and fdon't know if you can but it works so far:

Text
UPDATE TableA SET ClientSurname = LEFT(ClientName,CHARINDEX(',',ClientName)) UPDATE TableA SET ClientSurname = parsename(replace(ClientSurname,',',''),1) UPDATE TableA SET ClientInitial = Right(ClientName,CHARINDEX(',',ClientName)) 

The above puts the surname in the...


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>