Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to Break Data into two fields

Author  Topic 

AsimKhaliq
Yak Posting Veteran

94 Posts

Posted - 2004-03-18 : 11:50:01
Hi
I want to break my filed data into two field

Create table table1
(Name varchar(25),
Address varchar(50))

insert into values('Abc dcs','1234 keel')
insert into values('John Peep','123 keel')
insert into values('JPeep','124 keel')
insert into values(Null,'1234 keel')

So what i want to do is break name field into lastname and first name and put my data into another table.but if there isn't any space b/w
the name fild then it should be empty

So my new table will be like this
LastName|firstName|address
ABC|Dec|1234 keel
John|Peep|123 keel
JohnP||124 keel
||1234 keel

Thanks



SQLCode
Posting Yak Master

143 Posts

Posted - 2004-03-18 : 12:07:43
This might help
http://vyaskn.tripod.com/code.htm#split
Go to Top of Page

AsimKhaliq
Yak Posting Veteran

94 Posts

Posted - 2004-03-18 : 12:22:43
Thnks
But this doesn't help me atall, what I want is just to split my name field into 2 colums
like Jon Peep

Firstname= john
Lastname=Peep
I need a funtion to split or any funtion from which I can search space and split
Thnx
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-03-18 : 12:35:01
Have you looked at CHARINDEX to determine where the space is? You could then use that value to break them up using SUBSTRING.

Tara
Go to Top of Page
   

- Advertisement -