View previous topic :: View next topic
|
Author |
Message |
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Hi all,
I have got a requirement to find the column names belong to a particular creator say DBAT which has values as %<STRING2> % cosidering the string2 can be anywhere in the column
Is there any better idea rather creating a Dynamic sql which I had thought of??
I thought to list down all columns from SYSIBM.SYSCOLUMNS then using the output of first query thought of running another dynamic Sql statement to search for the occurence of the string %<string2>% So the count(*) would tell fields having the string will be greater or equak to one
If anyone can guide me for a better approach will be helpful
Thanks |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
in your where clause for the syscolumn select, only select char col as large or larger than you need to contain your search-string.
personally, i perfer the POSITION function POS(....) GT 0 to find the strings in each column. the pos value could be an offset for any substr function to update the column. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
Hi Dbz,
Thanks.
My string is something like '%&%.%'
But not sure how far POS will be effective sorry for not being more expressive on my String |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
can't use wildcards in the search key for POSITION or POSSTR.
though you could construct a lot of LIKE predicates,
being a bit&bytes type, i would
as you are pounding down thru the sysibmsyscolumns table cursor,
(sort by table, col pos, col len)
compare cursor_table to current_table in FROM clause
IF table name different, - combine all the stored
- SELECT's
- the FROM
- the WHERE/AND clauses
- write the sql to file
- CLEAR ALL build areas
end-if
i would take your searchkey mask, and isolate the literal searchkey(s) from the wildcards.
i recently did this kind of thing and found that allowing only one type of wildcard made things easier.
parse/unstring the searchkey
generate a POS for each
then build parenthetically enclosed AND/OR's
if you only have one searchkey part, then you only need one POS
problem is if you have more than one, the second can not start until the first is found/not found.
Code: |
WHERE POSSTR(column,part1) > 0
AND
POSSTR(column,part2) = 0
OR (
POSSTR(column,part1) > 0
AND
POSSTR(column,part2) > POSSTR(column,part1)
AND
POSSTR(column,part3) = 0
)
OR (
POSSTR(column,part1) > 0
AND
POSSTR(column,part2) > POSSTR(column,part1)
AND
POSSTR(column,part3) > POSSTR(column,part2)
AND
POSSTR(column,part4) = 0
) |
My code could generate unlimited sql for unlimited parts.
but that would get silly.
you would go out of your mind doing this by hand,
but you can generate a file containing all this sql,
then in batch, execute the sql, then parse the output sysouts |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
l would strongly advise againt
executing the sql in an interactive session/ in the foreground.
and,
keep in mind, the part1, part2 ...etc need to be replaced with an apostrophied-enclosed string/field contents. |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
|
|
I was planning to combine the Sql with some Rexx and execute |
|
Back to top |
|
|
|