简体   繁体   中英

Trying to remove user name from description column in SQL Server

Can someone please help with the below?

  1. I am trying to remove firstname and lastname from the description column and trying to move them to new columns
  2. The new description column should not contain firstname.lastname (it should contain only DELL 2009xftp DM0F532H7161888I793M NEW JERSEY )
  3. New columns: F_Name, L_Name, New_Description_without_FN_LN

Current sample data in the description column:

Firstname.Lastname DELL 2009xftp  DM0F532H7161888I793M NEW JERSEY

All 64k records have the same pattern like above.

if your data has the Firstname.Lastname and there are no spaces in the Firstname.Lastname then you can use CHARINDEX() , LEN() and RIGHT()

declare @var as varchar(50)
set @var = 'Firstname.Lastname DELL 2009xftp  DM0F532H7161888I793M NEW JERSEY'

select charindex(' ',@var)  --returns where the first space is; returns 19
select len(@var)            --returns the length of the string; returns 50
select right(@var,(len(@var)-charindex(' ',@var)))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM