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.
| Author |
Topic |
|
pnpsql
Posting Yak Master
246 Posts |
Posted - 2012-05-02 : 01:35:14
|
| hi team, i need to count only alphabets in string. please suggest.challenge everything |
|
|
rvdvarmacsit
Starting Member
2 Posts |
Posted - 2012-05-02 : 02:44:48
|
| try using LEN(LTRIM(RTRIM(@lString))) where @lString is the variable which contains the sting. |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-05-02 : 07:03:40
|
| Assuming that the string has non-alpha characters such as digits etc. and that you want to count only alpha characters, the only way I can think of is to remove the non-alpha characters and then take the length of the resulting string.To remove non-alpha characters, there is no set-based solution within T-SQL. You have to use a while loop (or go the route of CLR functions and Regex).Functions to strip characters are available if you google - for example here: http://blog.sqlauthority.com/2007/05/13/sql-server-udf-function-to-parse-alphanumeric-characters-from-string/ For your case, replace the pattern '%[^0-9A-Za-z]%' with '%[^A-Za-z]%' in the function listed in that blog. |
 |
|
|
|
|
|