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
 SQL Server Development (2000)
 Space

Author  Topic 

sardinka
Posting Yak Master

142 Posts

Posted - 2005-01-26 : 11:13:09
I have a fields with the space char in data.
How to find a space character in query?
'Smith David'

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-26 : 11:31:21
select *
from MyTable
where charindex(' ', col1) > 0

Go with the flow & have fun! Else fight the flow
Go to Top of Page

sardinka
Posting Yak Master

142 Posts

Posted - 2005-01-26 : 11:38:01
Sorry... I didn't clear my question....
I need to create a 2 columns from 1 columns where space is
Example:'Smith David'
'Smith' 'David'
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-26 : 11:43:49
[code]
declare @b varchar(50)
set @b = 'john smith'

select parsename(replace(@b, ' ', '.'), 2) as First_Name,
parsename(replace(@b, ' ', '.'), 1) as Last_Name

select left(@b, charindex(' ', @b)-1) as First_Name,
substring(@b, charindex(' ', @b)+1, len(@b)) as Last_Name

[/code]

Go with the flow & have fun! Else fight the flow
Go to Top of Page

sardinka
Posting Yak Master

142 Posts

Posted - 2005-01-26 : 14:49:17
it didn't work for if MI exist.
Kath M. Smith
Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2005-01-26 : 15:58:01
Define your requirements.

HTH

=================================================================

Our elections are free, it's in the results where eventually we pay. -Bill Stern, sports announcer (1907-1971)
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-01-26 : 16:36:29
well that's a little harder. you need to parse out 3 strings.
play with charindex and substring. my examples should give you some ideas...

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -