Interview Question in Microsoft Transact-SQL


 

Interview Question :: T-SQL question: how to count number of char in a text field


Dear All,

how can i use t-sql to count the number of char in a text field?

for example:
text: '123,Jimmy,Assigned a job, close the job'

I need to cout number of ',' in this text, so output for this example is 3

What is the code in T-SQL?

Many Thanks
Answers to "T-SQL question: how to count number of char in a text field"
RE: T-SQL question: how to count number of char in a text field?

select len(replace(txt,',',',,'))

-len(txt)

from(

select '123,Jimmy,Assigned a job, close the job' as txt

) x
 
Vote for this answer ::  
Update Alert Setting