|
|
|
Forum Member
      
Group: Forum Members
Last Login: 10/30/2008 8:36:55 AM
Posts: 34,
Visits: 48
|
|
Hello!
Would anyone have an easy way of counting the occurrences of a character within a character string?
So, if the string were AXFDXHAYSXDUSX you would get the result 2 for A, 4 for X, 1 for F, 2 for D and so on?
I cannot think of any defined functions that would do this. Perhaps there is a UDF or other workaround using a combination of functions?
Many thanks!!!
Andrew Livingston
Andrew C. Livingston
Teradata Certified Professional and Trainer
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: 11/12/2008 4:01:17 PM
Posts: 91,
Visits: 118
|
|
Three ways I can think of:
1. Write an UDF to evaluate
2. Write a SP to count them like you would in UDF
3. Use recursive SQL to iterate through each character and insert the character into a table. Then count the number of characters as select mychar, count(*) from foo group by 1;
|
|
|
|
|
Supreme Being
      
Group: Forum Members
Last Login: Today @ 6:49:01 AM
Posts: 180,
Visits: 578
|
|
UDFs will be the easiest, most usable and most efficient way!
Regards,
Adeel
|
|
|
|
|
Forum Member
      
Group: Forum Members
Last Login: 10/30/2008 8:36:55 AM
Posts: 34,
Visits: 48
|
|
Adeel/Jeff_O,
Thanks for your replies. I was thinking along the same line, but was hoping for some little known function in SQL. SQL isn't the best for string manipulation, but I suppose it is more meant for data manipulation!
Thanks!
Andrew
Andrew C. Livingston
Teradata Certified Professional and Trainer
|
|
|
|