Morpheus7
asked on
Remove first two characters and place in seperate field
Hi,
Is it possible to remove the first two characters from a table column and place those characters in another separate field.
The fields are both VARCHAR.
Any help would be appreciated.
Thanks
Is it possible to remove the first two characters from a table column and place those characters in another separate field.
The fields are both VARCHAR.
Any help would be appreciated.
Thanks
Sure:
UPDATE TableName
SET ColTwo = LEFT(ColOne,2),
ColOne = RIGHT(ColOne,LEN(ColOne)-2),
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
FYI, the separate column with only two characters would be more efficient as:
char(2)
rather than varchar(2).
char(2)
rather than varchar(2).
be aware that len will result in you losing trailing spaces from the column if that could be important to you.
you might want to use datalength instead which deals with numbers of bytes (which need to be divided by 2 if it is an NVARCHAR column)
you might want to use datalength instead which deals with numbers of bytes (which need to be divided by 2 if it is an NVARCHAR column)
ASKER
Thanks to all
from MyTable