View previous topic :: View next topic |
Author |
Message |
Ranjish Beginner

Joined: 22 Dec 2002 Posts: 64 Topics: 28 Location: Chennai
|
Posted: Tue Dec 07, 2004 10:23 am Post subject: Count of occurrence of a value in a table |
|
|
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 |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Tue Dec 07, 2004 10:27 am Post subject: |
|
|
Try
SELECT COUNT(*)
FROM MY.DB2TABLE
WHERE MYCOLUMN LIKE '%ABC%' |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Dec 07, 2004 10:37 am Post subject: |
|
|
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 |
|
 |
Ranjish Beginner

Joined: 22 Dec 2002 Posts: 64 Topics: 28 Location: Chennai
|
Posted: Tue Dec 07, 2004 10:44 am Post subject: |
|
|
Bithead,
Yes, my rqmt. is exactly as Kolusu mentioned. Is there any way of doing that through spufi?
regards
Ranjish |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Dec 07, 2004 10:57 am Post subject: |
|
|
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 |
|
 |
Bithead Advanced

Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Tue Dec 07, 2004 11:12 am Post subject: |
|
|
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 |
|
 |
Ranjish Beginner

Joined: 22 Dec 2002 Posts: 64 Topics: 28 Location: Chennai
|
Posted: Wed Dec 08, 2004 10:14 am Post subject: |
|
|
Kolusu,
Thank you for the fast reply. It is working perfectly.
regards
Ranjish |
|
Back to top |
|
 |
|
|