To insert only few characters | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

To insert only few characters

Hi, I am looking for a querry which will pick specific characters from a column and insert into another column. For ex: I have a table in which I have username and userlastname. The user names are entered as first letter of first name and full last name, like BDavidson. I would like to leave the first character (B) and insert the rest of the username (Davidson)in to the userlastname column. Few user names are also like firstname.lastname (Benjamin.Bluemle), in which case I want to enter the firstname into the userfirstname column (another column in the same table) and the last name into the userlastname column. Can anyone help me out with a querry. Thanks in advance. Madduri
quote:Originally posted by madduri Hi, I am looking for a querry which will pick specific characters from a column and insert into another column. For ex: I have a table in which I have username and userlastname. The user names are entered as first letter of first name and full last name, like BDavidson. I would like to leave the first character (B) and insert the rest of the username (Davidson)in to the userlastname column. Few user names are also like firstname.lastname (Benjamin.Bluemle), in which case I want to enter the firstname into the userfirstname column (another column in the same table) and the last name into the userlastname column. Can anyone help me out with a querry. Thanks in advance. Madduri

Look for SUBSTRING and CHARINDEX in BOL. That should give you an idea of how to extract strings.
Name
———
Dilli Grg (1 row(s) affected)
You may need to loop through your data based on your needs… declare @name sysname
select @name = ‘David.Thomas’ If @name like ‘%.%’
begin
select substring (@name, 1, charindex(‘.’, @name)-1) as firstname,
substring (@name, charindex(‘.’, @name)+1, len(@name)) as LastName
end
else
select substring (@name, 2, len(@name))
MohammedU.
Moderator
SQL-Server-Performance.com All postings are provided “AS IS” with no warranties for accuracy.

parsename also will be helpful Madhivanan Failing to plan is Planning to fail
]]>