| re: Split a column into 2 columns
"Prit" <prithwishmukherjee@hotmail.com> wrote in message
news:1105647534.836290.122080@z14g2000cwz.googlegr oups.com...[color=blue]
> Hi everyone
> I guess this should be a simple question for the gurus
> I have a Data in a column which is to be places in 2 columns instead of
> one. How do i go about doing it in MS SQL server? Could someone please
> help me. I could do it in access with an update query but things are a
> little different in SQL server so I am a little lost.
>
> Eg.
> Name
> John?Doe
> to be split into
> Name LastName
> John Doe
>
> Thanks in advance.
> Prit
>[/color]
You can use string functions:
declare @name varchar(20)
set @name = 'john?doe'
select left(@name, charindex('?', @name)-1), right(@name,
len(@name)-charindex('?', @name))
So something like this?
insert into dbo.Destination (fname, lname)
select left(fullname, charindex('?', fullname)-1), right(fullname,
len(fullname)-charindex('?', fullname))
from dbo.Source
Simon |