Counting the number of occurrences of a character within a character string
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


Counting the number of occurrences of a... Expand / Collapse
Author
Message
Posted 6/30/2008 12:12:03 PM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum 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
Post #12000
Posted 7/1/2008 3:58:47 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 11/25/2008 1:20:39 PM
Posts: 91, Visits: 119
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;
Post #12010
Posted 7/2/2008 12:34:50 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: Today @ 7:30:07 AM
Posts: 197, Visits: 611
UDFs will be the easiest, most usable and most efficient way!

Regards,

Adeel
Post #12011
Posted 7/4/2008 6:23:26 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum 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
Post #12038
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 2 ( 2 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 4:40pm

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.141. 9 queries. Compression Disabled.