MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Count of occurrence of a value in a table

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Ranjish
Beginner


Joined: 22 Dec 2002
Posts: 64
Topics: 28
Location: Chennai

PostPosted: Tue Dec 07, 2004 10:23 am    Post subject: Count of occurrence of a value in a table Reply with quote

Hi,

I am bot sure if I gave the subject correctly. Sorry if it is not clear. I will come to my problem.

There is a column in a DB2 table with length 3000 which holds some value. We need to know the occurrence of a particular value in the table. This can come multiple times in a row.

eg: ABC122ASASA ABC9383222

In the above value (shown for one row), I need to find out occurence of 'ABC'. But again, I need to find out the occurrence in the whole table.

The requirement was implemented in Cobol and want to cross check in SPUFI. Is there any way of doing this in SQL using SPUFI?

Thanks
Ranjish
Back to top
View user's profile Send private message
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Tue Dec 07, 2004 10:27 am    Post subject: Reply with quote

Try

SELECT COUNT(*)
FROM MY.DB2TABLE
WHERE MYCOLUMN LIKE '%ABC%'
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Dec 07, 2004 10:37 am    Post subject: Reply with quote

Bithead,

Count(*) is a column function and I don't think that is what ranjish wants. Ranjish wants to count the occurance of ABC horizontally !!

i.e if the table contains just one row like this
Code:

ABC122ASASA ABC9383222


Ranjish wants the count as 2 , since he has 2 abc in the string. The count(*) gives a count value of 1

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ranjish
Beginner


Joined: 22 Dec 2002
Posts: 64
Topics: 28
Location: Chennai

PostPosted: Tue Dec 07, 2004 10:44 am    Post subject: Reply with quote

Bithead,

Yes, my rqmt. is exactly as Kolusu mentioned. Is there any way of doing that through spufi?

regards
Ranjish
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Tue Dec 07, 2004 10:57 am    Post subject: Reply with quote

Code:

SELECT (LENGTH(COL) -                                           
        LENGTH(REPLACE(COL,'ABC',''))) / LENGTH('ABC')         
   FROM TABLE                                                           
;


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Bithead
Advanced


Joined: 03 Jan 2003
Posts: 550
Topics: 23
Location: Michigan, USA

PostPosted: Tue Dec 07, 2004 11:12 am    Post subject: Reply with quote

Nice!

I believe that this gives the total count:
Code:

SELECT SUM((LENGTH(COL) -                                           
        LENGTH(REPLACE(COL,'ABC',''))) / LENGTH('ABC'))
   FROM TABLE                                                           

This should also work in SPUFI:
Code:

SELECT COL
FROM TABLE
WHERE COL LIKE '%ABC%'

then issue the TSO command FIND ABC ALL in the resulting list and subtract 1 from the result to account for the display of the SQL.
Back to top
View user's profile Send private message
Ranjish
Beginner


Joined: 22 Dec 2002
Posts: 64
Topics: 28
Location: Chennai

PostPosted: Wed Dec 08, 2004 10:14 am    Post subject: Reply with quote

Kolusu,

Thank you for the fast reply. It is working perfectly.

regards
Ranjish
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group