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
 General SQL Server Forums
 New to SQL Server Programming
 needs to count char in a column

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-03-15 : 14:02:05
Hi all,

Can any one help me in writing a query in conuting the | char in a column.

select charindex('|',colum1,1)...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-15 : 14:03:55
[code]select column,len(column)-len(replace(column,'|','')) as charcount from table[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-03-15 : 14:37:54
Hi Visakh it is not giving me the correct count for | char in a column
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-03-15 : 14:41:33
Why?


declare @str varchar(40)
select @str='fg|sdf|00|fng|'

select len(@str)-LEN(replace(@str,'|',''))


PBUH
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-16 : 00:09:40
quote:
Originally posted by aakcse

Hi Visakh it is not giving me the correct count for | char in a column


first try it and see

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -