Split a field in MS SQL 2000

I have a varchar (40) field in a table that I would like to split.  The delimiter is a space.

 It currently looks like this --- >  datax datay

I want the end result to be a select statement that splits the field into two fields.  What is the best way to do this?  Note: what is in datax and datay is not constant meaning it could have different character lengths.  I don't see in sql the equivilent of split in visual basic.

Any help would be appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have a look at http://www.winnetmag.com/SQLServer/Article/ArticleID/21071/21071.html to create a split function in SQL
Scott PletcherSenior DBACommented:
You can use CHARINDEX() function to find a space in the column value.

--everything up to first space
SELECT LEFT(yourColumn, CHARINDEX(' ', yourColumn) - 1),  
--everything after the first space
    SUBSTRING(yourColumn, CHARINDEX(' ', yourColumn) + 1, LEN(yourColumn))
FROM ...

NOTE: If it's possible a space will not be present, this code needs changed.  Just let me know :-) .

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hopefully you don't have any spaces other that one, other wise things could get messy.
petantAuthor Commented:
Well I did have some records where that field is null.    I got the following error:
Invalid length parameter passed to the substring function.
What is the best way to only check for that field that is not null as part of the select statement ?
Use the ISNULL function to filter it out. You can look it up in Books online. It is simple to undrestand and use.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.