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
 Import/Export (DTS) and Replication (2000)
 counting segments within a string

Author  Topic 

ratheeshsql
Starting Member

17 Posts

Posted - 2006-05-24 : 06:42:49
hi,

there are a number of names in a table in which some may contain five segments. i got the idea to split it into five parts..
but my problem is that the splitting of the name must be done only if the name contains five segments..
i have been using the parseName method to check whether there is some text part at the fourth position or 3rd position and so on..
But the 'parseName' only supports upto 4 segments..

so how can i check whether a name contains five segments- all segments in names can be separated with spaces..

or plz tell me the method to count the spaces in a string after ltrim and rtrim methods are used.

reply plz

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-24 : 06:48:50
[code]select len(yourcol) - len(replace(yourcol, ' ', '')) as no_of_segments[/code]


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-24 : 09:48:04
If the result is 4, then you have 5 parts in that column

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -