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)
 No of comma

Author  Topic 

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-30 : 08:24:39
how to find the no.of comma in a string

for ex:
input
string='11,22,33,34,35'

output
4----Total no of commos

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-30 : 08:25:16
[code]select len(string) - len(replace(string, ',', ''))[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-30 : 08:25:57
quote:
Originally posted by VGuyz

how to find the no.of comma in a string

for ex:
input
string='11,22,33,34,35,'

output
4----Total no of commos


Shouldn't it be 5 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-30 : 08:28:14
declare @s varchar(100)
set @s='11,22,33,34,35'
select len(@s)-len(replace(@s,',',''))


Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-30 : 08:28:36


Madhivanan

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

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-30 : 09:26:50

Thanks for spending u'r time for me..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-07-31 : 09:56:29
quote:
Originally posted by VGuyz

how to find the no.of comma in a string

for ex:
input
string='11,22,33,34,35'

output
4----Total no of commos


What did you change in the question?

Madhivanan

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

VGuyz
Posting Yak Master

121 Posts

Posted - 2008-07-31 : 10:41:09
quote:


for ex:
input
string='11,22,33,34,35,'

output
4----Total no of commos



Removed the ','.
Thats all mathi.
Go to Top of Page
   

- Advertisement -